MATLAB Answers

Fat Man

How to get the size of a region in an image?

Asked by Fat Man
on 29 Jun 2019
Latest activity Commented on by Image Analyst
on 30 Jun 2019
How can I get the size of the green region in the image??
By using funtion any() and sum() on my mask index
Or any other ways that the experts can come up with.
Thank you for your help.
img1 = imread(pic)
red1 = img1(:,:,1);
green1 = img1(:,:,2);
blue1 = img1(:,:,3);
get_green = red1 == 0 & green1 == 255 & blue1 == 0;
sup_mask = cat(3,get_green,get_green,get_green);


Sign in to comment.




2 Answers

Answer by KALYAN ACHARJYA on 29 Jun 2019
Edited by KALYAN ACHARJYA on 29 Jun 2019
 Accepted Answer

I can counts the number of pixels of that region
%Please note that white portion also there in both side of fridge
% Crop it or you can discard specifically
[rows colm]=size(im)
threshold_vale=?? % sme value try with the image
% Segmnet the Green part
% Now you have binary image with white "1" pixels, on that green region
% You can replicate that number in cm also with co-relate with size of the original image
If you looking for length, in such case, if you know the complete size of fridge,
then you can comparitively find it from tot_pix and rows*colm of the fridge.
Hope it helps!


sum(binary_image) will give a row vector.
@Image_Analyst Edited Sir

Sign in to comment.

Answer by Image Analyst
on 29 Jun 2019

To get the size in pixels of your green mask, do this:
greenAreaInPixels = nnz(get_green)


Thank you. How can I get the dimension (number of rows and columns) of the green image?
[rows, columns, numberOfColorChannels] = size(im)
The green channel has the same number of rows and columns as the original RGB image.

Sign in to comment.