help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Separating image band alters histogram


From: Carnë Draug
Subject: Re: Separating image band alters histogram
Date: Sat, 29 Sep 2012 16:51:22 +0200

On 29 September 2012 04:48, Terry Duell <address@hidden> wrote:
> Hello All,
> For various reasons, I have been extracting the bands from RGB images, and
> it appeared to me that the band intensity levels were not as expected.
> As a test I recombined the bands of an image, and compared the new RGB with
> old. The new image has more intense colours than the old, confirming my
> feeling that something was happening to the band histograms.
> The code for the little test is as follows...
> --------------------
> % Octave - Terry Duell Sep 2012
> % separate bands, then recombine to check result
>
> fprintf('Reading image...\n')
>
> % for image a
> % read the first image
> % Extract the red, save as greyscale
> I1 = imread('images-2/a-1.jpg');
> I1 = double(I1(:,:,1:3))/256;
> imwrite(mat2gray(I1(:,:,1)),'sep-band/red.jpg','Quality',100);
> imwrite(mat2gray(I1(:,:,2)),'sep-band/grn.jpg','Quality',100);
> imwrite(mat2gray(I1(:,:,3)),'sep-band/blu.jpg','Quality',100);
>
> fprintf('written bands...\n')
>
> fprintf('Reading bands...\n')
>
> % for image a
> % read the first image red, then green, blue
>
> IA(:,:,1) = double(imread('sep-band/red.jpg'))/256;
> IA(:,:,2) = double(imread('sep-band/grn.jpg'))/256;
> IA(:,:,3) = double(imread('sep-band/blu.jpg'))/256;
>
> imwrite(IA,'sep-band/allbands.jpg','Quality',100);
>
> fprintf('Done...\n')
> -------------------
> I have played around with writing out the array IA as-read, and conversion
> to double, but that doesn't make any difference to the result.
>
> Is there a way to do this and end up with images that match in all respects?

I don't understand the problem, it's the purpose of mat2gray to change
the histogram since it sets the minimum and max to the minimum and max
of the image. Unless the min and max of your image are 0 and 1, they
will be changed.

If you want to get each channel without modification, just pass the
channel, without any function.

imwrite (I1(:,:,1)), "sep-band/red.tif");

Does that works?

Also, when you have an image of the uint8 class and wish to convert it
to class double, you should divide by 255 and not 256. Or use
im2double which already thinks about this things for you.

Carnë


reply via email to

[Prev in Thread] Current Thread [Next in Thread]