MATLAB Answers

NN
0

Locating points on the figure that correspond to a specific number on the colormap

NN
さんによって質問されました 2019 年 7 月 17 日
最新アクティビティ Adam Danz
さんによって コメントされました 2019 年 7 月 18 日
I've opened a .m figure that was generated earlier.
openfig('MapSurface.fig')
Next, I would like to know the xy position of the points on the figure that exactly match with 100 on the colorbar.
This could either be a pixel or list of pixels (as per their xy position) that correspond to 100, or, a marked region on the figure that highlights all points corresponding to 100.MapSurface.png
Note: I'm doing this as my final aim is to calculate the area of the spot size by knowing the location of its boundaries. In other cases the spot size is bigger or an arbitary shape. I've taken the simplest case for this question.
Thank you.

  2 件のコメント

Adam Danz
2019 年 7 月 17 日
Do you know how the image was created? imagesc()?
NN
2019 年 7 月 17 日
I used the following code for it
A = [200 200 200 200 200; 200 200 200 200 200; 200 200 100 200 200; 200 200 200 200 200; 200 200 200 200 200];
Percent_matrix = flipud (A);
Percent_Interp = imresize(Percent_matrix,200,'bilinear');
pcolor(Percent_Interp)
shading interp
caxis([0 200])
(The colorbar is a custom one as the predefined ones in matlab didnt have the one i wanted)

サインイン to comment.

製品


リリース

R2018b

1 件の回答

回答者: Adam Danz
2019 年 7 月 17 日
編集済み: Adam Danz
2019 年 7 月 17 日
 採用された回答

In this functional example below, the colorbar value (cval) is set to 140.0 which is within the yellow-green spectrum of the colorbar. The tolerance (tol) is set to 0.5 meaning that any value within 140 +/- 0.5 is accepted. A tolerance of 0 only accepts exact matches which will likely fail.
The "CData" (color data) is pulled from the figure and the code identifies which coordinates are within tolerance to your selected color value. Black markers are plotted showing the matches.
figure()
A = [200 200 200 200 200; 200 200 200 200 200; 200 200 100 200 200; 200 200 200 200 200; 200 200 200 200 200];
Percent_matrix = flipud (A);
Percent_Interp = imresize(Percent_matrix,200,'bilinear');
pcolor(Percent_Interp)
shading interp
caxis([0 200])
colorbar();
cval = 140.0; %colorbar value
tol = .5; %tolerance (accepts all values tval+/-tol); use 0 for no tol.
% get color data from the only object on the axis
ax = gca(); %handle to axis that contains the data
cdata = ax.Children.CData; % assumes axis only has 1 object!
% Alternative: cdata = ax.Children.ZData;
% determine which coordinates match selected color value
cidx = cdata >= (cval-tol) & cdata <= cval+tol;
% get the (x,y,z) coordinates of the slected color regions
x = ax.Children.XData; % assumes axis only has 1 object!
y = ax.Children.YData; % assumes axis only has 1 object!
[yidx,xidx] = find(cidx); % *
xSelect = x(xidx);
ySelect = y(yidx);
% mark selected units on figure
hold on
h = plot(xSelect, ySelect, 'ks', 'MarkerFaceColor', 'k','markersize', 2);
% delete(h)

  6 件のコメント

NN
2019 年 7 月 18 日
I tried your updated code for different cases and it works perfectly.
Thanks a ton!
Cheers.
NN
2019 年 7 月 18 日
Oh and I like your suggestion of using contourf().
Its a more neater representation but instead of all the different colour patterns getting contours, if only points corresponding to 100 get a contour then that would do the job.
So basically it would be a representation of all the 100 corresponding points falling within the marked boundary.
Adam Danz
2019 年 7 月 18 日
Check out the "levels" input to contourf() where you can set the number of contrours.

サインイン to comment.



Translated by