Matlab GUI changing image brightness using slider
Show older comments
i created programme than loads image, and i need to change its brightness and then save it. All buttons work, but im struggling with changing the brightness, sadly it doesnt work. Could someone help me state where is my mistake in the code bellow?
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, ~, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename pathname] = uigetfile({'*.jpg';'*.bmp'},'File Selector');
fullname=[pathname, filename];
ImageFile=imread(fullname);
axes(handles.axes1)
imagesc(ImageFile);
axis off;
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, ~, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
toBeSaved=getframe(gca);
[fileName, filePath] = uiputfile('*.bmp', 'Save As');
fileName = fullfile(filePath,fileName);
imwrite(toBeSaved.cdata, fileName, 'bmp');
guidata(hObject,handles);
% --- Executes on slider movement.
function slider1_Callback(hObject, ~, handles)
% hObject handle to slider1 (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
axes(handles.axes1);
val=0.5*get(hObject, 'value')-0.5;
imbright=(handles.axes1)+val;
axes(handles.axes1);
imshow(imbright);
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, ~, handles)
% hObject handle to slider1 (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
Accepted Answer
More Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!