DSPRelated.com
Forums

color image

Started by Laiq Azam July 26, 2007
Hello all,

Does anybody have a simple code of reading and processing a color image in
matlab, taking average of pixel (4 next pixels left and right).....

I would appreciate any feedback....

Thanks.

--
Laiq
Though it is not my field I think u need to work in HSV domain. There is a comamnd called rgb2hsv() in Immage processing toolbox
Hello Laiq, I try write this code:
%==================================================%

A = imread('C:\Documents and Settings\ESA\Desktop\pagar.jpg');
imshow(A);
[m,n] =size(A);
nd3 = n/3;
R_layer = A(1:m,1:nd3,1);
G_layer = A(1:m,1:nd3,2);
B_layer = A(1:m,1:nd3,3);

subplot(2,2,1), imshow(A);
subplot(2,2,2), imshow(R_layer);
subplot(2,2,3), imshow(G_layer);
subplot(2,2,4), imshow(B_layer);

Variable A will saving an color image matrix. This matrix contains three
layers, those are Red, Green, and Blue. You can save each layers in three
different variables (R_layer, G_layer, B_layer). So you can process them
depend on your need.

okay, I hope my question can solve your problem.

regards,

Esa

%==================================================%
On 7/24/07, Laiq Azam wrote:
>
> Hello all,
>
> Does anybody have a simple code of reading and processing a color image in
> matlab, taking average of pixel (4 next pixels left and right).....
>
> I would appreciate any feedback....
>
> Thanks.
>
> --
> Laiq
>
>
Hi,

You can read a color image just like any other:
X=imread('imagename.extension');

If you want to access the individual RGB grayscale frames you can do:
R= X(:,:,1);
G= X(:,:,2);
B= X(:,:,3);

and taking the average is similar to smoothing so you can simply create and use a smoothing filter like this:

filter1= 1/9.*[1 1 1; 1 1 1; 1 1 1];

This is a 3x3 filter. If you want a 4x4 one just do:
filter2= 1/16 .*[1 1 1 1; 1 1 1 1; 1 1 1 1; 1 1 1 1];

Then apply the filters on each of the RGB frames:

NewR= conv2(R,filter);
NewG= conv2(G,filter);
NewB= conv2(B,filter);

To combine these back into a colored image to see your end colored image you do:

FinalColor= cat(3, NewR, NewG, NewB);

figure,imshow(FinalColor);

Hope this helps!

Laiq Azam wrote:
Hello all,

Does anybody have a simple code of reading and processing a color image in matlab, taking average of pixel (4 next pixels left and right).....

I would appreciate any feedback....

Thanks.

--
Laiq