Using GUI to Edit Image

조회 수: 5 (최근 30일)
K F
K F 2020년 8월 27일
편집: KALYAN ACHARJYA 2020년 8월 27일
I want to make a GUI window that allows the user to change the threshold value of a binarized of an image and see the output. The GUI would show the binarized image, a text box, and a button. The inital image would use the default Matlab threshold value. If the user was unhappy with it, they could type a new thresholding value in the text box and push the button to update the image.
The code I have written is capable of doing, but only once. I want to user to be able to update the image with a new value as many times as they want. What sort of edits can I make to allow for this?
figure
iptsetpref('ImshowInitialMagnification',50)
img_data=imcomplement(imbinarize(mat2gray(raw_data)));
handles.img_1=imshow(img_data)
%make the text box
edit_box_h = uicontrol('style','edit',...
'units', 'normalized',...
'position', [0.45 0.1 0.05 0.05]);
%make the button
but_h = uicontrol('style', 'pushbutton',...
'string', 'Update Thresholding',...
'units', 'normalized',...
'position', [0.4 0 0.2 0.1],...
'callback', {@thrs_img, edit_box_h, img_data,lvl_data});
%Function code located in a separate file -------------------------------------------------------------
function thrs_img(~,~,edit_box_h, img_data, raw_data)
str_entered = get(edit_box_h, 'string'); %get the user text input
dbl_entered = str2double(str_entered);
if dbl_entered>0 && dbl_entered<1
img_data1=imcomplement(imbinarize(mat2gray(raw_data),dbl_entered)); %binarize using the new threshold value
handles.img_1=imshow(img_data1)
end
  댓글 수: 1
Mario Malic
Mario Malic 2020년 8월 27일
편집: Mario Malic 2020년 8월 27일
I think you need to have a callback to update your variable edit_box_h when you change its value. I am not sure if functions share their variables, so you can use make a public property instead and pass it on.
I am not sure how one does it in GUI, since I did not use it. If there's a numeric box in GUI, use that one, also, there's a possibility for such box to limit its acceptable numeric range.

댓글을 달려면 로그인하십시오.

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 8월 27일
편집: KALYAN ACHARJYA 2020년 8월 27일
I am providing here the alternate option, now a days I rarely do GUI (Guide option). MATLAB have great appdesigner features, you can do it with 5 minutes. Please enter appdesigner in command window, see the layout of the new window or see any basic tutorial, you can do it easily.
Like in your case, please note this the partial code of callback function
function ConvertButtonPushed(app, event)
im=rgb2gray(imread('test_image.png'));
imshow(im,'parent',app.UIAxes);
th=app.ThresholdValueSlider.Value;
bwImage=im2bw(im,th);
imshow(bwImage,'parent',app.UIAxes2);
end
Cheers!

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by