MATLAB MATLAB help: determining the area under a plot (not a curve whose form is known)

AI Thread Summary
The discussion revolves around a project involving image analysis, specifically focusing on plotting histograms and calculating areas under curves in MATLAB. The user seeks clarification on the correct approach to plotting histograms and determining the area under the curve. It is confirmed that using the MATLAB command 'trapz' is appropriate for calculating the area under the histogram generated by 'imhist(x)'. However, there is a distinction made between using 'trapz' directly on the histogram data versus applying it to a plot of the histogram. The consensus is that 'trapz(imhist(x))' is the correct method to obtain the area under the histogram, rather than using 'trapz(plot(imhist(x)))', which may not yield the desired results. The discussion emphasizes the importance of accurately plotting the histogram to ensure the area calculation reflects the actual data.
maverick280857
Messages
1,774
Reaction score
5
Hi

For a project (described https://www.physicsforums.com/showthread.php?t=227684"), I have to do the following for N images:

1. plot the histogram of each image, using

imhist(x)

2. plot a curvilinear approximation to the histogram, using

plot(imhist(x))

3. determine the area under the plot generated in step 2

4. Plot a curve of area value versus image number (index) and determine the image number for which the area value is a minimum.

I am not sure how to do step 3 and also whether steps 1 and 2 are correct.

Can someone please help?

Thanks and cheers
vivek
 
Last edited by a moderator:
Physics news on Phys.org
If step 2 is continuous then try the MATLAB command 'trapz'.
Go:
help trapz
in the MATLAB command window. Hopefully you can do:
trapz(imhist(x))
 
Should I do

trapz(imhist(x))

or

trapz(plot(imhist(x))

?

plot(imhist(x)) plots the histogram with the peaks joined by a not-so-smooth curve...
 
You should do:
trapz(imhist(x))

Now you say that plot(imhist(x)) plots a histogram with peaks joined by a curve? I assume you want the area under that curve? If that's the case I don't think trapz will help - you need to JUST plot the peaks and trapz will give the area under that curve.
 
Thanks
 

Similar threads

Back
Top