Getting non-existent pixel values

4 次查看(过去 30 天)
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.

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 Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by