can anyone explain this code? what is meant by imagesc?

5 views (last 30 days)
for a = 1:size(video,4)
imagesc(video(:,:,:,a));
axis image off
drawnow;
end;
  7 Comments
Jan
Jan on 27 Mar 2017
Edited: Jan on 27 Mar 2017
@sai likhitha GOdina: Please do not post a question multiple times. Do you see my answer in your thread https://www.mathworks.com/matlabcentral/answers/332153-can-anyone-explain-this-code-this-code-is-related-to-my-project-crowd-density-estimation? It was a complete waste of time to type this, because Image Analyst has explained it already very good.
This is very basic Matlab code. Please read the Getting Started chapters of the documentation and https://matlabacademy.mathworks.com/ . It would not be efficient to explain the absolute basics in the forum, when there are very good tutorials available already.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 27 Mar 2017
imagesc() is a display routine that scales the image to your display range (0-255) and displays it in the current (last used) axes. Your video is a 4-D array where the last index is the frame number. For RGB images I don't believe imagesc() does any scaling, though for gray scale images it does. So imagesc() is just like image() and imshow() for color images. I always use imshow() since for gray scale images imagesc() applies some weird colormap by default (though not for color images).
The third index is the color channel: 1 for red, 2 for green, and 3 for blue. This code does not have any comments and used not very descriptive variable names so it may be hard to understand what's going on. video(:,:,:,a) is the a'th frame of the video and it will be a full color RGB image. The colon means "all", so it's all rows, all columns, and all 3 color channels, which means a full color image.
The code could be written clearer like this:
% Get the total number of video frames.
totalNumberOfFrames = size(video,4)
% Loop over all frames displaying them as fast as possible.
for frameNumber = 1 : totalNumberOfFrames
thisColorFrame = video(:, :, :, frameNumber);
imagesc(thisColorFrame);
axis image off
drawnow; % force immediate repainting of the screen.
end

More Answers (1)

Tom Pryke
Tom Pryke on 27 Mar 2017
Its displaying the data contained in the array 'video' to whatever the current figure or axes object is. The 4th dimension of video contains the number of frames and the others presumably contain the image data.
  2 Comments
Guillaume
Guillaume on 27 Mar 2017
You're asking extremely basic questions. Honestly, if you can't figure out for yourself what it means, you stand no chance of being able to write your own code.
Jan's provided a very good link in your identical question to the getting started tutorial. Grabbing a book on matlab from your favourite library would help as well.

Sign in to comment.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!