How to find the (pixel) dimensions of images on a white background
Show older comments
Hello there,
I have a folder of 60 images of irregular household items that are greyscale on a white 500x500 pixel canvas. I need to have the images rescaled (will do in photoshop) to match the average size of a different set of images. Using MATLAB, I found the references images have 1.51 times more non-white pixels (i.e. image pixels) than the items do and need to alter these images to match the size. However, because the images are of vastly different items (i.e. a paperclip vs a closet), they vary a lot by dark pixel count.
How can I find the dimensions (height and width) of these images in MATLAB. I've included an example of an image being
samplePic = imread(img_dir + "/hn_processed");
image_double = im2double(samplePic); % turn all white pixels to 1
% I tried the below code by it didn't do what I wanted
actual_image = find(image_double ~= 1);
[rows, columns, numberOfColorChannels] = size(actual_image);
used. Thank you!

2 Comments
Matthew Peoples
on 6 Apr 2021
Adam Danz
on 8 Apr 2021
As long as the strawberry is oriented vertically or horizontally, the simple approach in my solution gives you to width and height.
Accepted Answer
More Answers (0)
Categories
Find more on Image display and manipulation 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!