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

3 次查看(过去 30 天)
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);
fridge2.png

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-6-29
编辑:KALYAN ACHARJYA 2019-6-29
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
im=rgb2gray(imread('image_name'));
[rows colm]=size(im)
threshold_vale=?? % sme value try with the image
binary_image=im<threshold_vale
% Segmnet the Green part
% Now you have binary image with white "1" pixels, on that green region
tot_pix=sum(binary_image(:));
area_green_part=tot_pix/(rows*colm)
% You can replicate that number in cm also with co-relate with size of the original image
or
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!

更多回答(1 个)

Image Analyst
Image Analyst 2019-6-29
To get the size in pixels of your green mask, do this:
greenAreaInPixels = nnz(get_green)
  2 个评论
Fat Man
Fat Man 2019-6-30
Thank you. How can I get the dimension (number of rows and columns) of the green image?
Image Analyst
Image Analyst 2019-6-30
[rows, columns, numberOfColorChannels] = size(im)
The green channel has the same number of rows and columns as the original RGB image.

请先登录,再进行评论。

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by