how to make a mini photoshop
1 view (last 30 days)
Show older comments
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 Comments
Answers (3)
reza hamzeh
on 9 Dec 2019
2 Comments
Lin JingHeng
on 9 Jun 2020
Excuse me, l have the same question when doing a project, do you know how to solve it now?
Image Analyst
on 13 Jun 2020
See Steve Eddins's blog series :Don't Photoshop it...MATLAB it!
0 Comments
DGM
on 10 May 2021
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 Comments
See Also
Categories
Find more on Explore and Edit Images with Image Viewer App in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!