Changing Sensitivity of 'Imbinarize' using a slider

8 ビュー (過去 30 日間)
Georg Edelmann
Georg Edelmann 2020 年 2 月 28 日
コメント済み: Georg Edelmann 2020 年 3 月 3 日
Hey guys,
I´m binarizing Images using Matlab and try to figure out the right sensitivity value for each image. Therefore a slider would be quite useful.
How could this be done?
Here is my code so far.
clf()
I= imread('Bild_1.jpg'); %input
I=I(:,:,1); %Selecting a colour
I = imbinarize(I,'adaptive','ForegroundPolarity','dark','Sensitivity',sens); %turn grayscale image in binary image
%sens is my variable
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)
sens=sld.Value
drawnow()
end
I hope you can help me.
Greetings
Here is a related question i asked about the sliders

採用された回答

Divya Gaddipati
Divya Gaddipati 2020 年 3 月 3 日
You can store the figure handle in a variable using uiaxes which can be passed to the changeSensitivity function to modify the binarization according to the changed sensitivity factor.
You can modify your code to something similar to as the following:
clc; clear; close all;
I= imread('peppers.png'); %input
I = I(:,:,1); %Selecting a colour
fig = uifigure;
cg = uiaxes(fig, 'Position', [50, 70, 500, 300]);
imshow(I, 'parent', cg);
sld = uislider(fig, 'Position', [100 50 300 50], 'Value', 1, 'Limits', [0,1],...
'ValueChangedFcn', @(sld, event)changeSensitivityFcn(event, cg, I));
function changeSensitivityFcn(event, cg, I)
sens = event.Value;
cg.Children.CData = im2uint8(imbinarize(I, 'adaptive', 'ForegroundPolarity', 'dark', ...
'Sensitivity', sens));
drawnow();
end
Hope this helps!
  1 件のコメント
Georg Edelmann
Georg Edelmann 2020 年 3 月 3 日
Thanks
you made my Day!

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by