필터 지우기
필터 지우기

calculate the area percent of non white pixel in the image

조회 수: 2 (최근 30일)
Sumit Chaudhary
Sumit Chaudhary 2018년 3월 25일
댓글: Image Analyst 2018년 3월 25일
In an ongoing project of mine, i have to calculate the area percent of all the pixel having not white coloration. The color is basically green and the shades of green. I have written code for area percentage for green coloration but it dont seem to work. The area percentage it is showing for all the 5 sub images to be 0.33 . Please help me out. I read something related to pure rgb color. Please tell how to check in my image the colors are pure or not.
I = imread('image.jpg');
av = zeros(1,5);
for i = 1:5
imshow(I) ;
[rgbImage, rect] = imcrop(I);
imwrite(rgbImage,strcat(num2str(i),'.jpg')) ;
greenChannel = rgbImage(:, :, 2);
[rows, columns] = size(rgbImage);
greenCount = sum(greenChannel(:) > 0);
greenareapercent(i)= greenCount / (rows * columns);
end

채택된 답변

Image Analyst
Image Analyst 2018년 3월 25일
Unfortunately you haven't read this link, and so haven't included 'image.jpg'.
I don't know what your definition of green is. Is it any pixel in which the green signal is more than the red and blue signal? Is it only pixels with an RGB value of (0, 255, 0)?
About all I can say is to convert your image to HSV with rgb2hav, and threshold on the hue channel to get pixels with a green hue. See color segmentation demos in my File Exchange for demos https://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862&sort=downloads_desc
  댓글 수: 3
Sumit Chaudhary
Sumit Chaudhary 2018년 3월 25일
gray= rgb2gray(I); [x y] = size( gray); imshow(gray);
now this gray intensities are my region of interest.
Image Analyst
Image Analyst 2018년 3월 25일
Use my hue segmentation tool here: https://www.mathworks.com/matlabcentral/fileexchange/28512-simplecolordetectionbyhue-- to find any green items.
You can also use the Color Thresholder app on the Apps tab of the MATLAB toolribbon to find green things. Use HSV color space.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by