Tuesday, June 10, 2008

Reducing Image Color

Original Image(1)
(2)
(3)
(4)
(5)

Original Image(1)
(2)
(3)
(4)
(5)
(1) To convert to an image with only 64 colors:
A=imread("originalpic.jpg");
B=255*floor((A)/85)*85;
C=double(B)/255;
imwrite("newcolor64.png",C(:,:,1),C(:,:,2),C(:,:,3))

(2) To convert to an image with only 27 colors:
A=imread("originalpic.jpg");
BB=255*floor((A)/86)*86+42;
CC=double(BB)/255;
imwrite("newcolor27.png",CC(:,:,1),CC(:,:,2),CC(:,:,3))

(3) To turn an image into a greyscale image:
A=imread("originalpic.jpg");
B3=(A(:,:,1)+A(:,:,2)+A(:,:,3))/3;
imwrite("greynow.png",B3)

(4) To turn the greyscale image into one with only 64 intensity values:
E=floor(double(B3)/4)*4;
imwrite("grey64.png",E)

(5) To turn the greyscale image into one with only 16 intensity values:
F=floor(double(B3)/16)*16;
imwrite("grey16.png",F)

4 comments:

Mike Zabrocki said...

I'm not confident about your 64 and 16 grayscale pictures. What is going on there that you can't see anything. Maybe it isn't saving it correctly. Not only that I think that there seems to be something wrong with the 256 greyscale values too.

Mike Zabrocki said...

by the way, I thought we got imwrite to work! is it still washing out your colors?

Math Girl said...

Imwrite washes out colors sometimes, and sometimes not. Matrix values don't seem to affect when the image is washed out or not...I dunno..

No luck with greyscale yet.

Math Girl said...

The method used to fix the washing out issue when creating the photomosaic worked here also. Need to save a file as .png whenever color values are being changed. Also, it doesn't hurt to double(A)/255 when using imwrite.