Creating a GUI to dictate caxis values

5 ビュー (過去 30 日間)
Greg
Greg 2022 年 4 月 22 日
コメント済み: Greg 2022 年 4 月 25 日
Greetings,
I am looking to create a GUI that would help with image analysis, therefore I wanted to implement interactive sliders that would change the values of the colormap limits using caxis. (changing the 'contrast')
Is it possible to implement variables (for example: caxis([cmin cmax])) that would be defined by the position of the slider when the user moves it, and automatically update the image plot?
Here's an excerpt of my code (different sliders for different plots)
figure ('Position', [200 50 850 200])
subplot(1,3,1);
imagesc(im2);
title('Interface 1'); caxis([cmin1 cmax1]);
subplot(1,3,2);
imagesc(im5);
title('Ratio'); caxis([cmin2 cmax2]);
subplot(1,3,3);
imagesc(im3);
title('Interface 2'); caxis([cmin3 cmax3]);
I have also created a GUI format through the 'guide' command.
Thank you!

採用された回答

Voss
Voss 2022 年 4 月 22 日
Yes. Define callback functions for your sliders. In the callback functions, get the 'Value' of the slider and use that to set the appropriate 'CLim' value of the corresponding axes. For example:
% your code excerpt, except storing the figure and axes in a
% handles structure using guidata
f = figure ('Position', [200 50 850 200]);
ax = subplot(1,3,1);
imagesc(im2);
title('Interface 1'); caxis([cmin1 cmax1]);
ax(end+1) = subplot(1,3,2);
imagesc(im5);
title('Ratio'); caxis([cmin2 cmax2]);
ax(end+1) = subplot(1,3,3);
imagesc(im3);
title('Interface 2'); caxis([cmin3 cmax3]);
handles.f = f;
handles.ax = ax;
guidata(handles.f,handles);
% this callback sets CLim(1) of the axes handles.ax(1)
function slider1_Callback(src,evt)
handles = guidata(src);
val = get(src,'Value');
climits = get(handles.ax(1),'CLim');
climits(1) = val;
set(handles.ax(1),'CLim',climits);
end
You need to make sure the 'Min' and 'Max' properties of the sliders are set appropriately so that the 'Value' of the slider corresponds to the 'CLim' value you want to set on the axes; otherwise you need to do some linear transform between slider 'Value' and 'CLim' value.
Also, you can likely use a single callback function for all the sliders (not the one defined above though - it would need some additional logic to determine which axes and which index of CLim to apply to, perhaps by using additional input arguments).
  3 件のコメント
Rik
Rik 2022 年 4 月 25 日
For general advice and examples for how to create a GUI (and avoid using GUIDE), have look at this thread.
You aren't creating a slider yet; you need the uicontrol function to do so.
Also, why did you edit the get call in the callback? Your version will error, since [0 1] is not a property name.
Greg
Greg 2022 年 4 月 25 日
I read the thread and found my solution there, now the sliders are displayed and are working as intented. Thank you for your help!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by