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

3 visualizaciones (últimos 30 días)
Darreon Schwartz
Darreon Schwartz el 11 de Abr. de 2017
Comentada: Image Analyst el 13 de Abr. de 2017
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

Respuestas (2)

dpb
dpb el 12 de Abr. de 2017
Editada: dpb el 12 de Abr. de 2017
[~,ix]=sort(distanceArray(:)); % get order vector of distances in the distance array
plot(distanceArray(ix),intensityArray(ix)) % plot in ascending order
  2 comentarios
Darreon Schwartz
Darreon Schwartz el 12 de Abr. de 2017
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 el 12 de Abr. de 2017
Editada: dpb el 12 de Abr. de 2017
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...

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 12 de Abr. de 2017
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;

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by