MATLAB: How to clasify the color of each specific pixel to some constant

colorimageimage analysisimage processing

Hello , I have this image where I have to relate the color of each pixel to some known constant. Let's say, red(including all pixels that are reddish, slightly red, etc.)=STRONG pixels; yellow(in the region of yellow)=WEAKER pixels; and so on… I have to do this for each pixel of my image and the problem I'm having is there are so many possibilities of getting a color somewhat red/reddish/pinkish (with rgb values being different) & all of them must be under the same STRONG pixels category.I've tried coding by taking ranges of values for rgb differenes, but I believe there should be another/clearer way to do so, which won't leave any pixel that is not in the range I've specified. My code is as following:
RedPIXELS='1010-808kPa';
YellowPIXELS='700-600kPa';
img=imread('1.jpg');
for k=1:vidHeight-1
if img(k,k,1)>250 && img(k,k,1)-img(k,k,2)>100 && img(k,k,1)-img(k,k,3)>100
img(k,k)=RedPIXELS;
if img(k,k,2)-img(k,k,1)<50 && img(k,k,3)<10
img(k,k)=YellowPIXELS;
end
end
end

Best Answer

No, there is no simpler or clearer way to do it along the lines you are proceeding, not if you want accuracy. The names that people associate with various RGB colors never form regular regions in RGB space, so you would have to code a lot of comparisons if you want to proceed like you are.