From: Nooshin on
Hi dear friends,

I have an image(I) of size 1944*2592*3 (unit8)
I've extracted a contour from this image using the following code:

>> contour = roipoly(I, I.x, I.y);
this code returns a black and white image of size 1944*2592 logical

Now I want to draw the following histograms from this contour but I don't know how to write the codes:

RGB (3*16); RGB(16*16*16)
HSI(3*16); HSI(16*16*16)

Dose anyone of you can help me, PLEASE?
Thanks alot
From: ImageAnalyst on
Can you get the coordinates of your contour and then multiply it by
your image (to mask it), and then use imhist() on each color channel
independently?
From: Nooshin on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <f616f774-5014-4126-be9d-cdbe5a958676(a)h9g2000yqa.googlegroups.com>...
> Can you get the coordinates of your contour and then multiply it by
> your image (to mask it), and then use imhist() on each color channel
> independently?

Thanks for your reply.
Yeah, I've done masking using this code:
>> contour = roipoly(I, I.x, I.y);
but my question is how to extract different histogram types:
RGB(3x16), RGB(61x16x16), HSI(3x16), HSI(16x16x16)
because this code returns a 2D black and white image (1944*2592 logical).
From: ImageAnalyst on
Like I said, just use masking. You have a color image to start with.
Then you get contours of some kind and you know the location of the
contours because you say you have a logical / binary image that has
those locations in it. Then you simply multiply to get the colors of
the original image in the masked area. Like this demo :

% Demo macro to very, very simple color detection in RGB color space
% by ImageAnalyst
clc;
close all;
% figuresc(0.9, 0.8);
% Read standard MATLAB demo image.
rgbImage = imread('onion.png');
% Display the original image.
subplot(3, 4, 1);
imshow(rgbImage);
title('Original RGB Image');
% Maximize figure.
set(gcf, 'Position', get(0, 'ScreenSize'));
% Split into color bands.
redBand = rgbImage(:,:, 1);
greenBand = rgbImage(:,:, 2);
blueBand = rgbImage(:,:, 3);
% Display them.
subplot(3, 4, 2);
imshow(redBand);
title('Red band');
subplot(3, 4, 3);
imshow(greenBand);
title('Green band');
subplot(3, 4, 4);
imshow(blueBand);
title('Blue Band');
% Threshold each color band.
redthreshold = 68;
greenThreshold = 70;
blueThreshold = 72;
redMask = (redBand > redthreshold);
greenMask = (greenBand < greenThreshold);
blueMask = (blueBand < blueThreshold);
% Display them.
subplot(3, 4, 6);
imshow(redMask, []);
title('Red Mask');
subplot(3, 4, 7);
imshow(greenMask, []);
title('Green Mask');
subplot(3, 4, 8);
imshow(blueMask, []);
title('Blue Mask');
% Combine the masks to find where all 3 are "true."
redObjectsMask = uint8(redMask & greenMask & blueMask);
subplot(3, 4, 9);
imshow(redObjectsMask, []);
title('Red Objects Mask');
maskedrgbImage = uint8(zeros(size(redObjectsMask))); % Initialize
maskedrgbImage(:,:,1) = rgbImage(:,:,1) .* redObjectsMask;
maskedrgbImage(:,:,2) = rgbImage(:,:,2) .* redObjectsMask;
maskedrgbImage(:,:,3) = rgbImage(:,:,3) .* redObjectsMask;
subplot(3, 4, 10);
imshow(maskedrgbImage);
title('Masked Original Image');



Just extract the individual color channels (like I did at the
beginning) from maskedrgbImage and call imhist() on each one.

For HSI, it's the same process, just transform your RGB image into HSI
before you start.
From: Nooshin on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <ca008018-9f5e-4107-9290-1c4c3d5593cc(a)c3g2000yqd.googlegroups.com>...
> Like I said, just use masking. You have a color image to start with.
> Then you get contours of some kind and you know the location of the
> contours because you say you have a logical / binary image that has
> those locations in it. Then you simply multiply to get the colors of
> the original image in the masked area. Like this demo :
>
> % Demo macro to very, very simple color detection in RGB color space
> % by ImageAnalyst
> clc;
> close all;
> % figuresc(0.9, 0.8);
> % Read standard MATLAB demo image.
> rgbImage = imread('onion.png');
> % Display the original image.
> subplot(3, 4, 1);
> imshow(rgbImage);
> title('Original RGB Image');
> % Maximize figure.
> set(gcf, 'Position', get(0, 'ScreenSize'));
> % Split into color bands.
> redBand = rgbImage(:,:, 1);
> greenBand = rgbImage(:,:, 2);
> blueBand = rgbImage(:,:, 3);
> % Display them.
> subplot(3, 4, 2);
> imshow(redBand);
> title('Red band');
> subplot(3, 4, 3);
> imshow(greenBand);
> title('Green band');
> subplot(3, 4, 4);
> imshow(blueBand);
> title('Blue Band');
> % Threshold each color band.
> redthreshold = 68;
> greenThreshold = 70;
> blueThreshold = 72;
> redMask = (redBand > redthreshold);
> greenMask = (greenBand < greenThreshold);
> blueMask = (blueBand < blueThreshold);
> % Display them.
> subplot(3, 4, 6);
> imshow(redMask, []);
> title('Red Mask');
> subplot(3, 4, 7);
> imshow(greenMask, []);
> title('Green Mask');
> subplot(3, 4, 8);
> imshow(blueMask, []);
> title('Blue Mask');
> % Combine the masks to find where all 3 are "true."
> redObjectsMask = uint8(redMask & greenMask & blueMask);
> subplot(3, 4, 9);
> imshow(redObjectsMask, []);
> title('Red Objects Mask');
> maskedrgbImage = uint8(zeros(size(redObjectsMask))); % Initialize
> maskedrgbImage(:,:,1) = rgbImage(:,:,1) .* redObjectsMask;
> maskedrgbImage(:,:,2) = rgbImage(:,:,2) .* redObjectsMask;
> maskedrgbImage(:,:,3) = rgbImage(:,:,3) .* redObjectsMask;
> subplot(3, 4, 10);
> imshow(maskedrgbImage);
> title('Masked Original Image');
>
>
>
> Just extract the individual color channels (like I did at the
> beginning) from maskedrgbImage and call imhist() on each one.
>
> For HSI, it's the same process, just transform your RGB image into HSI
> before you start.

Thanks so much for the answer.
But could you please explain me the difference between RGB(3*16) and RGB(16*16*16)
and their codes?!
 |  Next  |  Last
Pages: 1 2 3
Prev: pdepe: discontinuous source
Next: Rayleigh Fading