which function should i use for a slider to adjust the contrast of an image.

2 views (last 30 days)
I've created a slider to adjust the brightness, now i have to create another for contrast. Which function should i use?
Brightness slider function:
% --- Executes on slider movement. function slider_brightness_Callback(hObject, eventdata, handles) % hObject handle to slider_brightness (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
A = get(handles.slider_brightness,'Value');
AFMimage = handles.AFM_Adjust; a = get(hObject,'Value'); BadjAFMimage = imadd(AFMimage,a); handles.AFM_BAdjust = BadjAFMimage;
axes(handles.axes1); imshow(BadjAFMimage); axes(handles.axes4); imhist(BadjAFMimage);
set(handles.slider_brightness,'Value',A); set(handles.Btext,'String',num2str(A));
imwrite(BadjAFMimage,'Enhance Image.jpg','jpg')
% Update handles structure guidata(hObject, handles);
% --- Executes during object creation, after setting all properties. function slider_brightness_CreateFcn(hObject, eventdata, handles) % hObject handle to slider_brightness (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end

Answers (1)

Image Analyst
Image Analyst on 21 Jan 2014
I'd probably call imadjust() to have the slider change the image. Or you could just change the colormap and apply that, or you could call intlut(). However you want to do it.
  2 Comments
shane
shane on 22 Jan 2014
Changing the function to imadjust() doesn't seem to work.
When i clicked on the slider, no changes is done.
Error using imadjust>checkRange (line 296) Function imadjust expected its second input argument, [LOW_IN; HIGH_IN] to be a two-element vector.
Error in imadjust>parseInputs (line 260) checkRange(lowhigh_in, imageType, 2,'[LOW_IN; HIGH_IN]');
Error in imadjust (line 98) [img,imageType,lowIn,highIn,lowOut,highOut,gamma] = ...
Error in untitled10000>slider_contrast_Callback (line 374) BadjAFMimage = imadjust(AFMimage,a);
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in untitled10000 (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)untitled10000('slider_contrast_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Image Analyst
Image Analyst on 22 Jan 2014
Don't you think you just called it incorrectly? What do you think (the badly-named) a should be? Look at the help, then see what your slider value is, and construct a second argument for imadjust() that makes sense. I know you can do it because you're a smart engineer.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!