Control image transparency with a slider- appDesigner

Hi all,
I'm trying to control de tranparency of two images using a slider.
Currently, I don't know how to do the code for this feature with a callback function with the slider.
Can anybody help me?
What I wanted, for a better understanding, is that when I'm at a max value, I only see one of the images and at the min value I only see the other. Obviously, when I move the slider I want the transparency of them to change.
Thanks in advance
JM

3 件のコメント

Adam
Adam 2019 年 7 月 15 日
If you keep hold of the image handles on your main app object then it is simply a case of updating the AlphaData properties of each of the images to whatever you want in your slider callback, based on the current value of the slider.
João Mendes
João Mendes 2019 年 7 月 15 日
First of all, thanks.
I'm a truly begginer and I didn't fully understand your point.
Could you please explain that to me with some code examples?
Sorry and thanks
Adam
Adam 2019 年 7 月 15 日
It would be easier if you post the relevant code you currently have. I don't really have time for long answers from scratch, hence me adding a comment rather than an 'Answer'

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

 採用された回答

Adam Danz
Adam Danz 2019 年 7 月 15 日
編集済み: Adam Danz 2021 年 2 月 10 日

0 投票

This should get you started.
Two images are plotted on top of each other. A slider is added that sets the AlphaData of the top image.
% Create a figure with two images overlayed
fig = uifigure('HandleVisibility','on');
[X,cmap] = imread('corn.tif');
imshow(X,cmap);
hold on
[X2,map] = imread('peppers.png');
img2 = imshow(X2,map);
% Create a GUI with a slider that controls the 'AlphaData' value of the currently selected object
sld = uislider(fig,'Position',[50,50,300,3],'Value',1,'Limits',[0,1],...
'ValueChangingFcn', @(sld,event)changeTransparencyFcn(sld,event,img2),...
'BusyAction', 'cancel');
% set the slider properties such as position etc....
% % https://www.mathworks.com/help/matlab/ref/uislider.html
function changeTransparencyFcn(~, event, hobj)
% hobj is the image object handle
set(hobj,'AlphaData', event.Value)
drawnow limitrate
end
Changes made to improve answer on Feb 9, 2021.

5 件のコメント

João Mendes
João Mendes 2019 年 7 月 15 日
Wow. Thank you very much!
Georg Edelmann
Georg Edelmann 2020 年 2 月 27 日
Hey geat job!
I am trying to do a simialr Job in Matlab. I´d like to change the Sensetitivy of 'imbinarize' using a slider.
Here is my Code so far.
clf()
I= imread('Bild_1.jpg');
I=I(:,:,1);
I = imbinarize(I,'adaptive','ForegroundPolarity','dark');%,'Sensitivity',0.0);
imshow(I);
fig = uifigure();
fig.Position([3,4]) = [400,75];
sld = uislider(fig,'Position',[50,50,300,50],'Value',1,'Limits',[0,1],...
'ValueChangedFcn', @(sld,event)changeSensitivityFcn(sld,event));
function changeSensitivityFcn(sld, event)
set(gco,'Sensitivity', sld.Value)
drawnow()
end
i hope you can help me
Thanks
Adam Danz
Adam Danz 2020 年 2 月 27 日
編集済み: Adam Danz 2020 年 2 月 27 日
"Sensitivity" is not a property of images. The line set(gco, PROPERTY, VALUE) sets a property of the current object. See this page for a list of image properties.
Georg Edelmann
Georg Edelmann 2020 年 2 月 27 日
Hey thanks for your quick response!
How else could it be done?
function changeSensitivityFcn(sld, event)
Sensitivity=sld.Value
drawnow()
end
Using this code, i am able to change my Sensitivity Parameter as i can see in the Command Window, but the image itself does not change. Why?
Thanks
Adam Danz
Adam Danz 2020 年 2 月 27 日
In my answer,
set(gco,'AlphaData', sld.Value)
the slider is controlling the AlphaData property values of the currently selected image.
The link I provided in my previous comment lists properties of images. I don't know what you define as "sensitivity". If you can't figure that out, it might be better to post a new questions since I have limited time right now (feel free to link to this answer).

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeUpdate figure-Based Apps についてさらに検索

質問済み:

2019 年 7 月 15 日

編集済み:

2021 年 2 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by