Creating a GUI to dictate caxis values
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Akzeptierte Antwort
Voss
am 22 Apr. 2022
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 Kommentare
Rik
am 25 Apr. 2022
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!