How to resize multiple images with the max height??

4 views (last 30 days)
How to resize multiple images with the max height of all images and rest of the images less than max height will be filled with zeros in both side(UP/DOWN). I am using some 1024x512x128 images and using intensity difference, I am getting the ROI of the images, in this case I am having multiple height with same width eg. 458x512, 355x512, 600x512 , to make another .mat file I am using cell matrix as of the variation on height its not possible to use normal save to .mat option, tried but didnt work. Now I need to replace all the images into same height using the max height and smaller heights needs to be filled with 0's (I am using padarrays for that conversion and it works fine) but im having problem with getting the max height. any help appreciated .. thanks

Answers (1)

Image Analyst
Image Analyst on 1 Jul 2015
Edited: Image Analyst on 1 Jul 2015
You need to do the loop once and use size() to determine the max size of all the images. Then you need to do the loop again to resize the images using imresize(), padarray(), or some other method to standardize all the image sizes to the max size.
I don't see any need for any cell arrays or .mat files.
  3 Comments
Image Analyst
Image Analyst on 1 Jul 2015
If the image widths are 458, 355, 600, don't you want to make it so that they are all 600? If so, how do you know 600 is the biggest one unless you get all the sizes and check them? SO you can have a loop storing the maxSize. Why do you think you need a cell array?
maxRows = 0;
maxCols = 0;
for k = 1 : numberOfImages
% read images.....
[rows, columns, numberOfSlices] = size(thisImage);
if rows > maxRows
maxRows = rows;
end
if columns > maxCols
maxCols = columns;
end
end
Alex Taylor
Alex Taylor on 2 Jul 2015
Image Analyst's solution is nice in that you don't need to have all the images in memory at a time. You can determine their sizes one at a time, and keep updating maxRows and maxColumns.
If you have a very large number of images and speed is something you care about, you could potentially optimize this approach using IMFINFO to read your files headers instead of actually loading the contents of your image files into memory.
For example:
s = imfinfo('pout.tif');
rows = s.Height;
cols = s.Width;

Sign in to comment.

Categories

Find more on Image Processing and Computer Vision 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!