about the color of pixel
조회 수: 2 (최근 30일)
이전 댓글 표시
hi can any one tell me how can i count total no of yellow pixel in an image ? i want to find red ,yellow and black pixels value to find the accuracy of wound tissue.So pls help me in this
댓글 수: 0
답변 (1개)
Ayush
2024년 10월 23일
Hi,
To count the number of yellow, red, and black pixels in an image using MATLAB, you can convert the image to the HSV colour space for better colour discrimination, and then define thresholds to identify each colour. To convert the image to HSV color space you can use the “rgb2hsv” function. Refer to an example code below for a better understanding:
% Convert the image to HSV color space
hsvImg = rgb2hsv(img);
% Define thresholds for yellow color in HSV space
yellowMin = [0.10, 0.4, 0.4]; % Adjust these values as needed
yellowMax = [0.20, 1.0, 1.0]; % Adjust these values as needed
% Create a binary mask for yellow pixels
yellowMask = (hsvImg(:,:,1) >= yellowMin(1) & hsvImg(:,:,1) <= yellowMax(1)) & ...
(hsvImg(:,:,2) >= yellowMin(2) & hsvImg(:,:,2) <= yellowMax(2)) & ...
(hsvImg(:,:,3) >= yellowMin(3) & hsvImg(:,:,3) <= yellowMax(3));
% Count the number of yellow pixels
numYellowPixels = sum(yellowMask(:));
In the above example, I have provided a mask for yellow colour, in a similar way you can get a mask for red and black colour. For more information on the “rgb2hsv" function refer to the below documentation:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!