Creating a GUI to dictate caxis values
조회 수: 5 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!