Tuesday, June 24, 2008

Image Histograms in Scilab

Two solutions were found by my students to display the histogram of a grayscale (or indexed) image.

The first solution is a code written by Jeric
//Jeric Tugaff
//Histogram
im=imread('grayscale.jpg'); //opens a 24 bit image
im=im(:,:,1);imwrite(im(:,:), 'gs.jpg'); //converts to 8 bit grayscale
imageim=imread('gs.jpg');
val=[];
num=[];
counter=1;
for i=0:1:255
[x,y]=find(im==i); //finds where im==i
val(counter)=i; num(counter)=length(x); //find how many pixels of im have value of i
counter=counter+1;end
plot(val, num); //plot. :)

The second was found by Jorge, a built-in function

histplot([0:1:255],c);

where c is the image variable.

No comments: