필터 지우기
필터 지우기

how to make a mini photoshop

조회 수: 3 (최근 30일)
reza hamzeh
reza hamzeh 2019년 12월 8일
답변: DGM 2021년 5월 10일
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

답변 (3개)

reza hamzeh
reza hamzeh 2019년 12월 9일
plz help me
  댓글 수: 2
Lin JingHeng
Lin JingHeng 2020년 6월 9일
Excuse me, l have the same question when doing a project, do you know how to solve it now?
reza hamzeh
reza hamzeh 2020년 6월 13일
no sry

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2020년 6월 13일
See Steve Eddins's blog series :Don't Photoshop it...MATLAB it!

DGM
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],[]);

카테고리

Help CenterFile Exchange에서 Explore and Edit Images with Image Viewer App에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by