Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how to plot a image histogram to

Subject: how to plot a image histogram to

From: islinaismail@gmail.com

Date: 22 Mar, 2009 18:03:47

Message: 1 of 14

Hye...

My problem is how to convert the gray scale image into image histogram
so that i can analyze the intensity of the image pixels.The histogram
must consist of the vertical axis being a ratio between a pixel
intensity value of =93x=94 to the total number of pixels in an image. The
horizontal axis will contain the pixel value =93x=94.Can anyone help me on
the coding?

Really need a help from you guys!

Subject: how to plot a image histogram to

From: ImageAnalyst

Date: 22 Mar, 2009 18:38:31

Message: 2 of 14

On Mar 22, 2:03=A0pm, islinaism...@gmail.com wrote:
> Hye...
>
> My problem is how to convert the gray scale image into image histogram
> so that i can analyze the intensity of the image pixels.The histogram
> must consist of the vertical axis being a ratio between a pixel
> intensity value of =93x=94 to the total number of pixels in an image. The
> horizontal axis will contain the pixel value =93x=94.Can anyone help me o=
n
> the coding?
>
> Really need a help from you guys!
---------------------------------------------------------------------------=
------------------------
Have you tried the hist or imhist() function? To get precentage,
simply divide the array it returns by the number of pixels in your
array. I hope that's what you want, because what you actually
described is NOT the histogram despite you calling it that (you're
simply dividing the image by the number of pixels in the image). A
histogram is the COUNT of the number of pixels at an intensity value,
not the intensity value itself like you said.

Subject: how to plot a image histogram to

From: islinaismail@gmail.com

Date: 23 Mar, 2009 13:34:26

Message: 3 of 14

On Mar 22, 5:38=A0pm, ImageAnalyst <imageanal...@mailinator.com> wrote:
> On Mar 22, 2:03=A0pm, islinaism...@gmail.com wrote:> Hye...
>
> > My problem is how to convert the gray scale image into image histogram
> > so that i can analyze the intensity of the image pixels.The histogram
> > must consist of the vertical axis being a ratio between a pixel
> > intensity value of =93x=94 to the total number of pixels in an image. T=
he
> > horizontal axis will contain the pixel value =93x=94.Can anyone help me=
 on
> > the coding?
>
> > Really need a help from you guys!
>
> -------------------------------------------------------------------------=
--------------------------
> Have you tried the hist or imhist() function? =A0To get precentage,
> simply divide the array it returns by the number of pixels in your
> array. =A0I hope that's what you want, because what you actually
> described is NOT the histogram despite you calling it that (you're
> simply dividing the image by the number of pixels in the image). =A0A
> histogram is the COUNT of the number of pixels at an intensity value,
> not the intensity value itself like you said.

thanks for the response.Actually,i'm looking for how to plot image
pixel to histogram.I don't know how to doing the codes in GUI.Hope u
may help me....

Subject: how to plot a image histogram to

From: islinaismail@gmail.com

Date: 23 Mar, 2009 13:51:29

Message: 4 of 14

On Mar 23, 12:34=A0pm, islinaism...@gmail.com wrote:
> On Mar 22, 5:38=A0pm, ImageAnalyst <imageanal...@mailinator.com> wrote:
>
>
>
> > On Mar 22, 2:03=A0pm, islinaism...@gmail.com wrote:> Hye...
>
> > > My problem is how to convert the gray scaleimageintoimagehistogram
> > > so that i can analyze the intensity of theimagepixels.Thehistogram
> > > must consist of the vertical axis being a ratio between apixel
> > > intensity value of =93x=94 to the total number of pixels in animage. =
The
> > > horizontal axis will contain thepixelvalue =93x=94.Can anyone help me=
 on
> > > the coding?
>
> > > Really need a help from you guys!
>
> > -----------------------------------------------------------------------=
----------------------------
> > Have you tried the hist or imhist() function? =A0To get precentage,
> > simply divide the array it returns by the number of pixels in your
> > array. =A0I hope that's what you want, because what you actually
> > described is NOT thehistogramdespite you calling it that (you're
> > simply dividing theimageby the number of pixels in theimage). =A0A
> >histogramis the COUNT of the number of pixels at an intensity value,
> > not the intensity value itself like you said.
>
> thanks for the response.Actually,i'm looking for how toplotimagepixeltohi=
stogram.I don't know how to doing the codes in GUI.Hope u
> may help me....
Here is my codes:

% Convert color image to grayscale image

Y =3D rgb2gray(handles.b); %convert RGB to grayscale
axes(handles.axes3);
imshow(Y); %show grayscale image

% plot the image pixels to histogram
y =3D imread (Y);
imhist(y);
axes (handles.axes6);
imshow (y);

Subject: how to plot a image histogram to

From: Image Analyst

Date: 23 Mar, 2009 13:58:01

Message: 5 of 14

islinaismail@gmail.com:
I'll ask again: have you tried the hist or imhist() function? The imhist function requires the image processing toolbox, while hist() doesn't. These functions create a histogram.
Regards,
ImageAnalyst

Subject: how to plot a image histogram to

From: islinaismail@gmail.com

Date: 23 Mar, 2009 14:13:11

Message: 6 of 14

On Mar 23, 12:58=A0pm, "Image Analyst" <imageanal...@mailinator.com>
wrote:
> islinaism...@gmail.com:
> I'll ask again: have you tried the hist or imhist() function? The imhist =
function requires theimageprocessing toolbox, while hist() doesn't. =A0Thes=
e functions create ahistogram.
> Regards,
> ImageAnalyst

Yes,i had tried the imhist() function from image processing
toolbox.But,the histogram doesn't appear in axes.Here are my codes:

Z =3D imhist(Y);
axes(handles.axes6);
imshow(Z);

Subject: how to plot a image histogram to

From: Image Analyst

Date: 23 Mar, 2009 15:51:01

Message: 7 of 14

islinaismail@gmail.com
Don't use imshow to display the histogram. It is a distribution, not an image. Use the bar() command:
[PixelCounts, GLs] = imhist(imageArray, numberOfBins); % make sure you label the axes after imhist because imhist will destroy them.
bar(PixelCounts);
Good luck,
ImageAnalyst

Subject: how to plot a image histogram to

From: islinaismail@gmail.com

Date: 23 Mar, 2009 17:24:37

Message: 8 of 14

On Mar 23, 2:51=A0pm, "Image Analyst" <imageanal...@mailinator.com>
wrote:
> islinaism...@gmail.com
> Don't use imshow to display thehistogram. =A0It is a distribution, not an=
image. =A0Use the bar() command:
> [PixelCounts, GLs] =3D imhist(imageArray, numberOfBins); =A0 =A0% make su=
re you label the axes after imhist because imhist will destroy them.
> bar(PixelCounts);
> Good luck,
> ImageAnalyst


Thanks a lot...but,may i know what means by GLs?and what should i put
on PixelCounts if my image size was 240x240 pixels?How about the
imageArray?I'm still didn't get it..Plz help me...

Currently,my friend proposed me to do the following codes,but the
system doesn't works on her codes.I need your assist since i'm just a
beginner in Matlab..Thanks..

Z =3D Y ;

for n =3D 256;
imhist(Z,n);title('Image histogram for image pixel');
axes(handles.axes6);
bar(240*240);
end

Subject: how to plot a image histogram to

From: Image Analyst

Date: 23 Mar, 2009 18:08:01

Message: 9 of 14

islinaismail@gmail.com
What a crummy piece of code your friend wrote. He/she should learn more about how to program MATLAB. Here's a way to do it that WILL work:

clc;
close all;
imageArray = imread('Cameraman.tif'); % Open monochrome image.
subplot(1, 2, 1);
imshow(imageArray);
numberOfBins = 256;
[PixelCounts, GrayLevels] = imhist(imageArray, numberOfBins); % make sure you label the axes after imhist because imhist will destroy them.
subplot(1, 2, 2);
bar(PixelCounts);
maxGL = max(GrayLevels);
xlim([0 maxGL]);
msgbox('Please maximize this window.');

Subject: how to plot a image histogram to

From: islinaismail@gmail.com

Date: 23 Mar, 2009 18:47:19

Message: 10 of 14


> clc;
> close all;
> imageArray =3D imread('Cameraman.tif'); % Open monochromeimage.
> subplot(1, 2, 1);
> imshow(imageArray);
> numberOfBins =3D 256;
> [PixelCounts, GrayLevels] =3D imhist(imageArray, numberOfBins); =A0 =A0% =
make sure you label the axes after imhist because imhist will destroy them.
> subplot(1, 2, 2);
> bar(PixelCounts);
> maxGL =3D max(GrayLevels);
> xlim([0 maxGL]);
> msgbox('Please maximize this window.');


ok..thanks...but,what should i put for 'image name' file for
imageArray =3D imread('image name'); ?
because in previous, i'd declared an image as Y as a result for
converting RGB to grayscale image....here are the example of codes:

% Convert color image to grayscale image

Y =3D rgb2gray(handles.b); %convert RGB to grayscale
axes(handles.axes3);
imshow(Y); %show grayscale image

Hope you will guide me..thank a lot...

Subject: how to plot a image histogram to

From: Image Analyst

Date: 23 Mar, 2009 20:04:01

Message: 11 of 14

islinaismail@gmail.com
imageArray is your Y. Just use my code and replace imageArray with Y and you should be good to go.
Regards,
imageAnalyst

Subject: how to plot a image histogram to

From: islinaismail@gmail.com

Date: 24 Mar, 2009 02:54:03

Message: 12 of 14

Thanks...but,suddenly this error messages is appear :

Error in ==> guidemfile>@(hObject,eventdata)FAS
('pushbutton3_Callback',hObject,eventdata,guidata(hObject))
"Error while evaluating uicontrol Callback"

What should i do?
The histogram also didn't appear in the axes and as a result,the
following function (image filtering and thresholding process) can't
proceed as before..Why this happen?Im lost now...plz help me....here
are some of the codes :


%--------Executes when "DETECTION PROCESS" button is press--------
function pushbutton3_Callback(hObject, eventdata, handles,varargin)


% Convert color image to grayscale image

Y = rgb2gray(handles.b); %convert RGB to grayscale
axes(handles.axes3);
imshow(Y); %show grayscale image

% histogram

imageArray = imread(Y); % Open monochromeimage.
subplot(1, 2, 1);
imshow(imageArray);
numberOfBins = 256;
[PixelCounts, GrayLevels] = imhist(imageArray, numberOfBins); % make
sure you label the axes after imhist because imhist will destroy them.
subplot(1, 2, 2);
axes(handles.axes6);
bar(PixelCounts);
maxGL = max(GrayLevels);
xlim([0 maxGL]);
msgbox('Please maximize this window.');


% Filtering process

b = Y;

s=b;
m=mean(s);
n=mean(m);
for y=1:15
   i=16*y;
   p=i-15;
   for x=1:15
      j=16*x;
      q=j-15;
      t(1:16,1:16)=s(p:i,q:j);
      u=mean(t);
      v=mean(u);
         pkl=n/v;
.....
....
....
....
....

end

Subject: how to plot a image histogram to

From: ImageAnalyst

Date: 24 Mar, 2009 10:19:30

Message: 13 of 14

islinaism...@gmail.com
imread takes a filename, not an array. If you already have Y from
reading in some filename, then, like I said, just use your "Y" instead
of the word "imageArray," although I prefer more descriptive variable
names than the single letters you are using (that's why I can't follow
your filtering code easily - too cryptic).
Secondly, don't use subplot. If you're using a GUI with axes on it,
just use the axes() function to specify the current axes.
In your code for filtering, it doesn't even appear like it's using the
histogram at all (it doesn't use PixelCounts). I don't see
thresholding going on either.
-ImageAnalyst

Subject: how to plot a image histogram to

From: islinaismail@gmail.com

Date: 24 Mar, 2009 12:24:10

Message: 14 of 14

Ok...thanks a lot!!! I had followed your codes instruction and it's
run successfully in my system...!a big thanks for you.... ;)

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us