How can I draw a circular trend line in a heat map?

10 ビュー (過去 30 日間)
Cailey
Cailey 2025 年 5 月 5 日
編集済み: Adam Danz 2025 年 5 月 5 日
I am working on some analysis for a visual search experiment and am looking to make a trend line around the heat map. Something like this (I drew the oval by hand):
I am having trouble with how to do this, but I need it to help find proportions of the horizontal and vertical heights for my analysis.
Thank you!
  2 件のコメント
Torsten
Torsten 2025 年 5 月 5 日
What are the hard conditions about the region you want to encircle ? So far, you vaguely describe it as "trend line around the heat map".
Cailey
Cailey 2025 年 5 月 5 日
I apologize around that. I guess I don't have specific hard conditions right now, I am hoping that there was a common method for this. I am pretty new to these types of plots

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

採用された回答

Matt J
Matt J 2025 年 5 月 5 日
編集済み: Matt J 2025 年 5 月 5 日
If the trend line is supposed to be elliptical, you can use gaussfitn,
to fit a 2D gaussian surface to the map. Then use fcontour to overlay one of the Gaussian's elliptic isocontours (perhaps the half-maximum contour).
  2 件のコメント
Cailey
Cailey 2025 年 5 月 5 日
Thank you, I will look into this!
Matt J
Matt J 2025 年 5 月 5 日
編集済み: Matt J 2025 年 5 月 5 日
You're welcome, but if you find that it works, please Accept-click the answer.

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

その他の回答 (1 件)

Adam Danz
Adam Danz 2025 年 5 月 5 日
編集済み: Adam Danz 2025 年 5 月 5 日
This solution plots a contour line that was computed at a specific level using smoothed data and is plotted on top of the original image data.
1. Create noisy demo data. In this example, the 2D distribution is slightly elliptical.
x = linspace(-3,3,50);
data = exp(-(.6*x.^2+x'.^2)/2) + (rand(50)-.5)./4;
% For a circular 2D distribution: data = exp(-(x.^2+x'.^2)/2) + (rand(50)-.5)./4;
2. Plot the data as an image
m = imagesc(data);
axis equal tight
cb = colorbar;
3. Use contour to create a contour line at a specified level. I chose a level where green starts to turn into blue in the colorbar at y=0.5. Contour uses the marching squares algorithm which results in the thin black border line in the results below.
level = 0.5;
hold on
[cm,h] = contour(data,level+zeros(1,2), 'LineWidth',1,'color','k');
4. Re-compute the contour using smoothed data. I'm using imgaussfilt from the Image Processing Toolbox but you could also use smoothdata2. Note that smoothing the data may change the range of level. Change how much smoothing is applied by reducing or increasing the 2nd argument in imgaussfilt or the third argument in smoothdata2.
dataSmooth = imgaussfilt(double(data),2);
% Alternative: dataSmooth = smoothdata2(data,'gaussian');
[cm2,h2] = contour(dataSmooth,level+zeros(1,2), 'LineWidth',3,'color','r');
Here's an example of the same approach applied to a more complex terrain. I reduced the guassian filter from 2 sd to 1 (2nd argument in imgaussfilt).
data = peaks(50) + (rand(50)-.5);
figure;
imagesc(data)
colorbar
level = 2;
hold on
[cm,h] = contour(data,level+zeros(1,2), 'LineWidth',1,'color','k');
dataSmooth = imgaussfilt(double(data),1);
% Alternative: dataSmooth = smoothdata2(data,'gaussian');
[cm2,h2] = contour(dataSmooth,level+zeros(1,2), 'LineWidth',3,'color','r');

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by