Hello everyone, i'm new to matlab and i'm trying to implement slider for un sharp mask filter and i don't know how to do that. I implemented slide for brightess and my code in slider1_Callback function looks like this:
2 views (last 30 days)
Show older comments
global im
if(isempty(im))
h = msgbox('Please browse image file.');
else
val = 1 * get(hObject,'Value') - 1;
imbright=im+val;
axes(handles.axes1);
imshow(imbright);
end
0 Comments
Answers (1)
Geoff Hayes
on 20 Oct 2017
Dan - please clarify what (with the code you have provided) is the behaviour that you are observing. Is there any change to the image in the axes? Is there no change but a new figure opens?
Also, I recommend that you avoid using global variables like im. Just save the image (that the user has chosen) to the handles structure like
% in the function that picks the image
handles.im = im;
guidata(hObject, handles);
Then your above code would become
if ~isfield(handles, 'im')
msgbox('Please browse image file.');
else
val = 1 * get(hObject,'Value') - 1;
imbright=handles.im+val;
axes(handles.axes1);
imshow(imbright);
end
You may then want to save the updated image back to the handles structure so that the next time the slider moves, you use the already updated image to brighten or darken.
if ~isfield(handles, 'im')
msgbox('Please browse image file.');
else
val = 1 * get(hObject,'Value') - 1;
imbright=handles.im+val;
axes(handles.axes1);
imshow(imbright);
handles.im = imbright;
guidata(hObject, handles);
end
Note that I'm assuming that you are using GUIDE since you have referenced the handles structure.
See also continuous slider callback for a means to update the image when the slider moves and not just when it stops (like it would do for your callback).
1 Comment
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!