Retaining Original Resolution in Image Processing

4 views (last 30 days)
I'm working with a program that converts .avis to .bmps and analyzes them. However, the bmp images that it makes have resolutions that depend on the size of the figure window. Most of the .avis I'm working with are 640x480, but the resolutions of the .bmps are all over the place, and they aren't even all the same because the figure window size changes for no apparent reason. I really need to find a way to keep the resolution the same in the images as it was in the video, otherwise the calibration for the image analysis is worthless. Here's the code that I'm working with:
for k = 1:importnumber:nFrames
i = i+1;
im = read(vid,k);
im = im(:,:,1);
videofile(:,:,i) = im;
imagesc(videofile(:,:,i)),colormap(gray),axis;
F = getframe;
[im1,map] = frame2im(F);
imshow(im1);
filename = sprintf('%s %d.bmp',setname,i);
imwrite(im1,gray,filename,'bmp')
end

Accepted Answer

Image Analyst
Image Analyst on 25 May 2012
You need to set "hold on" or it will do that (adjust when each new image is put in). Be aware though that you're loading all the images in, covering up prior ones, so it uses more memory and will slow down.
What I'd do instead is to apply your colormap to im with ind2rgb() (instead of imagesc) and then save that (which will be the same size - the size of im) rather than getting the displayed image (which as you say adjusts after every image).
% Make custom colormap.
myColorMap = jet(256); % or whatever...
% Make it into a true color RGB image.
rgbImage = ind2rgb(im, myColorMap);
% Save to disk.
imwrite(rgbImage, filename);
Get rid of the getframe and frame2im stuff.
  3 Comments
Image Analyst
Image Analyst on 25 May 2012
It saves the actual image values. If your image only goes between 200 and 230 then yes, it will have low contrast. You can fix that by using imadjust() or intlut() on the image before saving it. To scale it for display, but not change the actual pixel values, use imshow(lowContrastImage, []); The [] will make it expand out the intensity region to take up the full 0-255.
Daniel
Daniel on 25 May 2012
I checked the intensity values and they ranged from 0 to 251. I think the issue was that I was trying to go from a "gray" image directly to rgb. I used gray2ind() before ind2rgb() and that seemed to work pretty well. Thanks for your help!

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 24 May 2012
Instead of using imagesc() on each step, record the handle of the first imagesc(), and then for all of the rest of the iterations, set() the CData property of that handle to be the new frame content.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!