Plotting mean of the columns of image on that image

10 ビュー (過去 30 日間)
Yawar Rehman
Yawar Rehman 2014 年 9 月 1 日
コメント済み: Yawar Rehman 2014 年 9 月 3 日
I am struggling to plot the mean of the columns of the gray scale image on the same image. Mean of the columns of an image can be found by using Mean command in Matlab, but i don't have any idea how to plot it in image coordinates. Any idea or help is appreciated! Thank you :)
  8 件のコメント
Yawar Rehman
Yawar Rehman 2014 年 9 月 3 日
i am not sure it is the correct answer though it is doing what i want! + i am curious if someone could suggest me a way for avoiding for loop

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2014 年 9 月 3 日
To do what you want without a loop:
[~, down] = min(abs(bsxfun(@minus, X, mean(X))));
bsxfun just subtract the column mean from every value in X, and then you take the index of the minimum of the absolute value of that difference.
  1 件のコメント
Yawar Rehman
Yawar Rehman 2014 年 9 月 3 日
kudos ... thank you guillaume

サインインしてコメントする。

その他の回答 (2 件)

Michael Haderlein
Michael Haderlein 2014 年 9 月 2 日
Actually, I believe he just gave exactly contradicting answers on Guillaume's question. As I get it, this is what the result should look like:
I did it with the following code, however, I have no idea why a more straight-forward way didn't work (maybe someone can tell me?):
img=imread('grayscaleexample.bmp');
figure, imshow(img)
ha=axes('color','none','position',get(gca,'position'));
tf=figure;
hp=plot(1:size(img,2),mean(img));
set(hp,'parent',ha)
set(ha,'xlim',[1,size(img,2)])
delete(tf)
So the idea is to create another axes above the ones showing the image and plot the mean of the grayscale there. For some reason (please help) I have to draw the plot somewhere else first and then copy it to the axes where it's shown finally. When I plot directly in the axes on top of the ones with the image, the image axes will be deleted - I have no idea why.
What I mean is the following:
>> figure, imshow(img)
>> axes('position',get(gca,'position'))
>> get(gcf,'children')
ans =
1.0e+03 *
1.4420
1.4370
>> plot(1:size(img,2),mean(img));
>> get(gcf,'children')
ans =
1.4370e+03
  7 件のコメント
Yawar Rehman
Yawar Rehman 2014 年 9 月 3 日
thank for the answer haderlein. i have commented on the question which i asked. can you please review it

サインインしてコメントする。


Guillaume
Guillaume 2014 年 9 月 2 日
編集済み: Guillaume 2014 年 9 月 2 日
If you do indeed want to plot the mean on the graph (i.e. the other option I offered) then:
imshow(img);
hold on
plot(1:size(img, 2), mean(img), 'r');
I'm not sure what you mean by having two portions of the image though.
  1 件のコメント
Michael Haderlein
Michael Haderlein 2014 年 9 月 2 日
oops, you're totally right with that, of course plotting in the same axes is possible. This axes deleting behavior confused me so much that I didn't think about this anymore ;-)

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by