フィルターのクリア

How do I plot one matrix as a function of another?

7 ビュー (過去 30 日間)
Darreon Schwartz
Darreon Schwartz 2017 年 4 月 11 日
コメント済み: Image Analyst 2017 年 4 月 13 日
I am trying to create a plot of intensity versus distance. I have one matrix containing distance values from a few points, created by bwdist. I have another matrix simply full of intensity values. They are the same size.
I would like a 2D plot exhibiting how intensity changes with distance from the points. The trouble I'm having is the plot function only plots columns of matrices against each other. I need to be able to plot an absolute distance as provided by the matrix with distance values, uninhibited by the column/row distinction.
Thank you

回答 (2 件)

dpb
dpb 2017 年 4 月 12 日
編集済み: dpb 2017 年 4 月 12 日
[~,ix]=sort(distanceArray(:)); % get order vector of distances in the distance array
plot(distanceArray(ix),intensityArray(ix)) % plot in ascending order
  2 件のコメント
Darreon Schwartz
Darreon Schwartz 2017 年 4 月 12 日
So this provided a plot, but I do not know what to make of it, as I do not understand what your code does. What is [~,ix]? And I'm not sure what it means to plot in ascending order, or why that would be helpful.
dpb
dpb 2017 年 4 月 12 日
編集済み: dpb 2017 年 4 月 12 日
I'm no image analyst so just a shot in the dark. You said had distances and intensities and wanted to plot the latter against the former but they're scattered around in an array.
So, [~,ix] just returns the position in the array of each distance in order to use in a plot that will relate whatever the intensity value represents to what each distance is.
Now, whether that means anything...that's an entirely different question. :)
Meanwhile it appears that the real Image Analyst did come along and has a klew; hopefully that is helpful. I read his code and don't know enough about the output of bwdist nor image processing as a discipline to follow it...

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


Image Analyst
Image Analyst 2017 年 4 月 12 日
I do this sometimes so I know what to do. Scan the array getting distance and gray level. Let's say your Euclidean Distance image is called edtImage and your gray scale image is called grayImage. Then do this (untested, off the top of my head)
[rows, columns] = size(edtImage);
maxDistance = sqrt(rows^2+columns^2);
profileVector = zeros(1, maxDistance); % Preallocate
countVector = zeros(1, maxDistance);
for col = 1 : columns
for row = 1 : rows
thisDistance = ceil(edtImage(row, column));
profileVector(thisDistance) = profileVector(thisDistance) + grayImage(row, column);
countVector(thisDistance) = countVector(thisDistance) + 1;
end
end
% Crop off unused elements
lastElement = find(countVector, 1, 'last');
profileVector = profileVector (1 : lastElement); % Crop
countVector = countVector(1 : lastElement); % Crop
% Convert counts to means
profileVector = profileVector ./ countVector;
% Now plot it.
plot(profileVector, 'b-', 'LineWidth', 2);
grid on;
title('Mean Gray Level vs. Distance', 'FontSize', 24);
xlabel('Distance', 'FontSize', 24);
ylabel('Mean Gray Level', 'FontSize', 24);
grid on;
  1 件のコメント
Image Analyst
Image Analyst 2017 年 4 月 13 日
I forgot that I already had a full demo of it. I'm attaching it now.

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

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by