how to get the area of a specific RGB value ?

7 views (last 30 days)
Hello community,
I am working on a project that requires me to find an area of an image selected. I have a code that highlights a certain part of an image needed in red, but I'm not sure how to find the value of the red area.
We tried converting he image into greyscale but it is not very precise.
Thank you so much if you have any idea about it.
more, these is my matlab test code :
clc; clear all; close all; rgbImage = imread('DSC_0093.JPG');
% RGB Area % - Red : ~150 ? 168 % - Green : ~ 105 ? 120 % - Blue : ~ 63 ? 73
fig = figure; imshow(rgbImage); dcm_obj = datacursormode(fig); set(dcm_obj,'DisplayStyle','datatip',... 'SnapToDataVertex','off','Enable','on') disp('Click on the picture to display a data position, then press Return.')
% Wait while the user does this.
pause
c_info = getCursorInfo(dcm_obj);
%get position cursor
position = c_info.Position;
RedChannel = rgbImage(:,:,1); GreenChannel = rgbImage(:,:,2); BlueChannel = rgbImage(:,:,3);
redmin = rgbImage(position(2),position(1),1)-15; redmax = rgbImage(position(2),position(1),1)+15;
greenmin = rgbImage(position(2),position(1),2)-15; greenmax = rgbImage(position(2),position(1),2)+15;
bluemin = rgbImage(position(2),position(1),3)-15; bluemax = rgbImage(position(2),position(1),3)+15;
for x = 1:1080 for y = 1:1620
if (((RedChannel(x,y))>redmin && (RedChannel(x,y))<redmax) && ((GreenChannel(x,y))>greenmin && (GreenChannel(x,y))<greenmax) && ((BlueChannel(x,y))>bluemin && (BlueChannel(x,y))<bluemax))
RedChannel(x,y) = 255;
GreenChannel(x,y) = 0;
BlueChannel(x,y) = 0;
end
end
end
rgbImage2 = cat(3, RedChannel, GreenChannel, BlueChannel); %imshow(rgbImage2, []);
%% test calculating area
BW = roipoly(rgbImage2);

Accepted Answer

Image Analyst
Image Analyst on 24 Jun 2015
It looks like you're doing segmentation in RGB color space. I have a demo for that in my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862, as well as in other color spaces, which are usually better.

More Answers (0)

Categories

Find more on Historical Contests 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!