Using the imhist function in Matlab to build multiple histograms in the same figure

I am new to Matlab and am trying to process the images a bit. I have two color images that I convert to shades of gray. My goal is to set the histograms for both grayscale images on the same figure so that I can compare them. My code is as follows:

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

The code is great for viewing two histograms independently, but I can find how to combine them into one digit for comparison. Please, help!

+4
source share
2 answers

If you want both to be on the same axis, and you don't mind losing the bottom panel, try this (I don't have 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') 
+4
source

Try it!

 figure (x), subplot(2,1,1); imhist(agray); subplot(2,1,2); imhist(bgray); 
0
source

Source: https://habr.com/ru/post/1495208/


All Articles