how to obtain the values
1 次查看(过去 30 天)
显示 更早的评论
Please could someone help me to get these two values....
1) The largest average intensity in the horizontal projection of an image (R1) and
2) The average intensity of zero from the top to bottom in the horizontal projection of an image (R2).
I'm working on Ultra-Sound images.... Please do reply....
0 个评论
采纳的回答
Thorsten
2013-1-16
Iorg = imread('./../../Downloads/r1r2.png');
I = rgb2gray(Iorg(58:242, 60:198, :));
m = mean(I, 2);
[notused R1] = max(m);
minthreshold = 0.3;
R2 = min(find(m < minthreshold));
subplot(2, 3, [1:3]), imshow(Iorg)
subplot(2,3,4), imshow(I)
subplot(2,3,5),
% plot vertical histogram
N = numel(m);
for i=1:N, line([0 m(i)], N-[i i]+1), end
axis tight
set(gca, 'PlotBoxAspectRatio', [1 size(I,1)/size(I, 2) 1])
set(gca, 'XTIck', [0:20:140])
set(gca, 'XAxisLocation', 'top')
set(gca, 'TickDir', 'out')
grid on
xlabel('Gray-level value')
ylabel('Image height')
subplot(2,3,6)
imshow(I)
line(xlim, [R1 R1], 'Color', 'y')
line(xlim, [R2 R2], 'Color', 'y')
更多回答(2 个)
Jan
2013-1-14
- What is the "horizontal projection of the image". The more precise the question, the more correct the answer ;-)
- Isn't the average intensity of zero equal to zero? And does "from the top to bottom" changes anything for this trivial fact?
Please post more details.
Image Analyst
2013-1-14
Use the sum or the mean function
verticalProfile = sum(yourArray(:,column1:column2), 1);
horizontalProfile = sum(yourArray(row1:row2, :), 2);
2 个评论
Image Analyst
2013-1-16
编辑:Image Analyst
2013-1-16
yourArray is the name of your array. What do you call the name of your image array variable? row1 is your R1, isn't it? And my row2 is what you call R2, don't you think? In general when you do something like yourArray(row1:row2, :), that's taking just the part of the yourArray image between row1 and row2 inclusive - this is standard basic MATLAB terminology. It gets a submatrix portion of the full size matrix. Does that explain it better?
Regarding histogram, you have not mentioned histogram before. You do realize that a histogram and a profile are two completely different things don't you? If you want the max of the vertical profile, you can do
maxIndexes = find(verticalProfile == max(verticalProfile));
maxValue = verticalProfile(maxIndexes(1));
Because there may be more than one location of the max (several elements have the same max value), that's why you don't want to use the max() function like some people may suggest. max() only gives you the first max it encounters.
If you really do want a histogram then you have to do
[pixelCounts, grayLevels] = imhist(yourArray(R1:r2,:),256);
Then to find the max of the counts (which gray level bin has the most counts (pixels)):
maxIndexes = find(pixelCounts== max(pixelCounts));
modeGrayLevel = grayLevels(maxIndexes(1));
To find the highest gray level
maxGL = max(max(yourArray(R1:r2,:)));
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!