Filter löschen
Filter löschen

can any one help me find area under a curve?

1 Ansicht (letzte 30 Tage)
Surya Gnyawali
Surya Gnyawali am 1 Jul. 2017
Kommentiert: Walter Roberson am 4 Jul. 2017
Hi, I have an RGB image I of size 1047x995 uint8, to integrate in matlab, using with trapz() or cumtrapz(). I separated the channels R, G, B. Now I plotted a curve that averages all columns and gives a curve. Now I need to find the area under the curve. Please help
The idea is to quantify a rgb image and it's red, green & blue channels.
  3 Kommentare
Surya Gnyawali
Surya Gnyawali am 3 Jul. 2017
Bearbeitet: Surya Gnyawali am 3 Jul. 2017
Hi Roberson, Thanks a lot for this help. It worked. I have two queations. 1) I only understand the difference between trapz() and cumtrapz() is: trapz() does integration of all trapizoids, gets a column of indivisual trapizoidal areas under the curve and sums to a single number(?), gives total area under the curve.But the cumtrapz() gives a column of these trapizoidal areas only. Can you please explain if I understood correcdtly? Is this area in mm^2. or depends on the resolution of the original images?
2) How I give credit to some like you by giving stars or 1-5 or anything else? Thanks Surya
Walter Roberson
Walter Roberson am 4 Jul. 2017
The formula for trapz(y) for vector y works out as
result = sum(y) - 1/2*(y(1) + y(end))
When the input is a vector, the result is a scalar.
The formula for cumtrapz(y) for vector y works out as
result = cumsum(y) - 1/2*(y(1) + y)
For example,
[ 0, x1/2 + x2/2, x1/2 + x2 + x3/2, x1/2 + x2 + x3 + x4/2, x1/2 + x2 + x3 + x4 + x5/2, x1/2 + x2 + x3 + x4 + x5 + x6/2, x1/2 + x2 + x3 + x4 + x5 + x6 + x7/2, x1/2 + x2 + x3 + x4 + x5 + x6 + x7 + x8/2, x1/2 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9/2, x1/2 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10/2]
"Is this area in mm^2. or depends on the resolution of the original images?"
For your purposes, neither. You are integrating mean intensity units over a width, so the area is going to be intensity units times pixels. Mean intensity units is found by integrating intensity units by pixels and then dividing by the length, so it has no remaining length unit.
I have no idea what you are going to use the result for.
If you had doing a 2D trapz then you could have been integrating intensity units over area, which would have given you a measure of total energy over the rectangular area, which could then be scaled according to the area of one square pixel -- if, that is, you knew the resolution.
Chances are that you do not know the resolution. If the picture was taken with most cameras, then if there is a resolution in the picture headers at all, it is likely to be 72, the common nominal pixels-per-inch of older displays (not of the camera itself.) DSLR with auto-focus just might happen to record enough information in the headers to do a reasonable pixel size estimate, by looking at the autofocus distance and the aperture and knowing the lens focal length, but you cannot really count on the image headers unless you are using a scientific camera with firmware developed for imaging applications (e.g., a precision microscope.)

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 1 Jul. 2017
? You mean like
red = YourImage(:,:,1);
red_int = cumtrapz( mean(red, 2 ) );
I am not at all sure what the point is in taking the integral of the mean of the red channel...
  2 Kommentare
Surya Gnyawali
Surya Gnyawali am 2 Jul. 2017
Bearbeitet: Walter Roberson am 2 Jul. 2017
You are right, the attached image is the red channel column wise averaged from a rgb image. This is a line plot of mean of each column of original matrix. I tried trapz() on this but gives error. I used
r = image(:,:,1);
pp = plot(mean(r));
pp.Color = 'red'; %line color
Int = cumtrapz(mean(r,2));
it give me a column of numbers how I get a single value of the intgral? May be here is wrong. What would be another option or correction to this?
Thanks
Walter Roberson
Walter Roberson am 2 Jul. 2017
I do not get an error with that code.
YourImage = imread('tape.png');
r = YourImage(:,:,1);
pp = plot(mean(r));
pp.Color = 'red'; %line color
Int = cumtrapz(mean(r,2));
What error do you observe?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by