Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using "imhist" function in Matlab to plot multiple histograms on the same figure

I'm new to Matlab and am trying to do a bit of image processing. I have two color images that I convert to grayscale. My goal is to be able to put the histograms for both grayscale images on the same figure so I can compare them. My code looks like this:

a=imread('image1.jpg')
agray=rgb2gray(a)
b=imread('image2.jpg')
bgray=rgb2gray(b)
figure,imhist(agray)
figure,imhist(bgray)

The code works fine for looking at the two histograms independently, but I can find how to combine them into one figure for comparison. Please help!!

like image 239
user2650768 Avatar asked Aug 04 '13 16:08

user2650768


People also ask

How does Imhist work in Matlab?

The imhist function creates a histogram plot by defining n equally spaced bins, each representing a range of data values, and then calculating the number of pixels within each range. You can use the information in a histogram to choose an appropriate enhancement operation.

How do you display a histogram of an image in Matlab?

I = imread('pout. tif'); Display a histogram of the image. Since I is grayscale, by default the histogram will have 256 bins.

How do you plot a 2d histogram in Matlab?

Description. histogram2( X,Y ) creates a bivariate histogram plot of X and Y . The histogram2 function uses an automatic binning algorithm that returns bins with a uniform area, chosen to cover the range of elements in X and Y and reveal the underlying shape of the distribution.


1 Answers

If you want both on the same axes and you don't mind loosing the lower bar, try this (I don't have the Image Toolbox right now, so I haven't tested it):

a=imread('image1.jpg')
agray=rgb2gray(a)
b=imread('image2.jpg')
bgray=rgb2gray(b)
[counts,x] = imhist(agray)
stem(counts,x,'b')
hold on
[counts,x] = imhist(bgray)
stem(counts,x,'r')
like image 184
Luis Mendo Avatar answered Sep 21 '22 15:09

Luis Mendo