how to make a mini photoshop
1 次查看(过去 30 天)
显示 更早的评论
hi. i wrote some codes to make a mini photoshop. a buttom to upload a pic. a slidbar for changeing brightness and a slidbar for changing contrastcontrast.
all work well but there is a problem. if i change the brightness(contrast), then when i want to change contrast(brightness) it will not affect to the pic that i changed. in fact it just affects on the orginal pic. how can i solve the problem ? plz help me.
function varargout = photoeditor(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @photoeditor_OpeningFcn, ...
'gui_OutputFcn', @photoeditor_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function photoeditor_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = photoeditor_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function insertpic_Callback(hObject, eventdata, handles)
[File_Name, Path_Name] = uigetfile({'*.jpg';'*.bmp';'*.png';},'Select Image','E:\installed programs\matlab\matlab\work\GUI\photoeditor');
if(File_Name~=0)
img=strcat(Path_Name,File_Name);
axes(handles.axes1);
imagefile=imread(img);
imshow(img);
handles.image =imagefile;
guidata(hObject, handles);
else
return;
end
function brightness_Callback(hObject, eventdata, handles)
if isfield(handles, 'image')
brightval=0.5*get(hObject, 'value')-0.5;
imbright=double(handles.image)+brightval;
imshow(uint8(imbright), 'Parent', handles.axes1);
guidata(hObject, handles);
end
function brightness_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function contrast_Callback(hObject, eventdata, handles)
if(isfield(handles,'image'))
low = get(hObject,'value');
high = 1;
imcontrast = imadjust(handles.image,[low high],[]);
imshow(uint8(imcontrast), 'Parent', handles.axes1);
guidata(hObject, handles);
end
0 个评论
回答(3 个)
reza hamzeh
2019-12-9
2 个评论
Lin JingHeng
2020-6-9
Excuse me, l have the same question when doing a project, do you know how to solve it now?
DGM
2021-5-10
This problem happens because both functions start over from the source image every time they are called.
imbright = double(handles.image)+brightval;
% ...
imcontrast = imadjust(handles.image,[low high],[]);
Instead of making a unique working image for each function, have one working image that's used by all functions. If you don't need to preserve a copy of the original source image, just use it. Otherwise, define a working image and write to it.
When loading a new image or reverting to the original:
handles.workingimg = handles.image;
When operating on it:
workingimg = double(handles.workingimg)+brightval;
% ...
workingimg = imadjust(handles.workingimg,[low high],[]);
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!