Getting non-existent pixel values

조회 수: 2 (최근 30일)
Douglas Brenner
Douglas Brenner 2016년 11월 6일
댓글: Image Analyst 2016년 11월 7일
After the following code, an image is displayed. It is black, white and red. However, if I use hpimpixelinfo(2) on the image I only get 1's and 0's. How do I address the pixels and find out which are black, white, or red.
colors=['r'];
for k=1:length(B),
b = B{k};
cidx = mod(k,length(colors))+1;
plot(b(:,2), b(:,1),...
colors(cidx),'LineWidth',1);
end

답변 (2개)

Image Analyst
Image Analyst 2016년 11월 6일
편집: Image Analyst 2016년 11월 6일
Douglas, you need to use impixelinfo(), not hpimpixelinfo(). And you probably need to adjust where it is so you can see it. And you're passing in 2. I wouldn't do that. I'd just call it right after you call imshow() to make sure you're using it on the right figure.
hp = impixelinfo();
hp.Unit = 'normalized';
hp.Position = [0.01, 0.98, 0.2, 0.1]; % [xLeft, yTop, width, height]
If that doesn't show the pixel values in the upper left of your figure, then adjust the position.
To find red, see my Simple Color Detection app in my File Exchange where I do exactly that. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Basically you can extract the color planes
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
and, if your red is exactly (255,0,0) then find those pixels like this
redPixels = redChannel == 255 & greenChannel == 0 & blueChannel == 0;
imshow(redPixels);
To find black (0,0,0) pixels:
blackPixels = redChannel == 0 & greenChannel == 0 & blueChannel == 0;
imshow(blackPixels);
To find white (255,255,255) pixels:
whitePixels = redChannel == 255 & greenChannel == 255 & blueChannel == 255;
imshow(whitePixels);
If your colors are not pure computer graphics like that, then see my File Exchange app, or see the Color Thresholder on the Apps tab of the tool ribbon.
  댓글 수: 1
Douglas Brenner
Douglas Brenner 2016년 11월 6일
I'll have to chew on this for awhile but should help. thanks.

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


Douglas Brenner
Douglas Brenner 2016년 11월 6일
편집: Douglas Brenner 2016년 11월 6일
Didn't work
Index exceeds matrix dimensions. Error in stddev (line 51) greenChannel = b(:, :, 2);
Is there a green plane? Only one color.
colors=['r']; for k=1:length(B), b = B{k}; cidx = mod(k,length(colors))+1; plot(b(:,2), b(:,1),... colors(cidx),'LineWidth',1)
And showing the red plane are commenting out the green and blue only shows 4 pixels
  댓글 수: 1
Image Analyst
Image Analyst 2016년 11월 7일
Then you don't have a color image. Maybe you have an indexed image. Your code looks like there is not image, just a plot, but since the code doesn't run, because B is not defined, it's hard to tell what it will look like. Please post either code that runs, your image or screenshot, or both code and image.

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

카테고리

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