Borrar filtros
Borrar filtros

Create Adjust Sharp Image Button

1 visualización (últimos 30 días)
Eiman Hakimy
Eiman Hakimy el 13 de En. de 2022
Comentada: Geoff Hayes el 13 de En. de 2022
Hello
I am doing an assignment where I need to put some filters. Now here I choose the brightness filter, smooth and also the sharperning filter.
I have managed to put the function on brightness and also smooth but on the sharperning part of the filter I did not succeed.
How do I want to put the Sharperning function where when the user presses on the "Less Sharp" button it will decrease sharperning while if the user presses "More Sharpening" it will add sharperning to the image.
Here my example GUI and also code.
% ASSIGNMENT2 MATLAB code for assignment2.fig
% ASSIGNMENT2, by itself, creates a new ASSIGNMENT2 or raises the existing
% singleton*.
%
% H = ASSIGNMENT2 returns the handle to a new ASSIGNMENT2 or the handle to
% the existing singleton*.
%
% ASSIGNMENT2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ASSIGNMENT2.M with the given input arguments.
%
% ASSIGNMENT2('Property','Value',...) creates a new ASSIGNMENT2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before assignment2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to assignment2_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help assignment2
% Last Modified by GUIDE v2.5 13-Jan-2022 16:51:17
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @assignment2_OpeningFcn, ...
'gui_OutputFcn', @assignment2_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
% End initialization code - DO NOT EDIT
function setImg(val)
global img
img = val;
function r = getImg
global img
r = img;
% --- Executes just before assignment2 is made visible.
function assignment2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to assignment2 (see VARARGIN)
% Choose default command line output for assignment2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes assignment2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = assignment2_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in UploadImage.
function UploadImage_Callback(hObject, eventdata, handles)
% hObject handle to UploadImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
try
[a b] = uigetfile('*.*', 'All Files');
img = imread ([b a]);
imshow(img, 'Parent', handles.axes1);
setImg (img);
catch me
end
% --- Executes on button press in MoreBrightness.
function MoreBrightness_Callback(hObject, eventdata, handles)
% hObject handle to MoreBrightness (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
try
img = getImg;
I = imadd(img,10);
imshow(I, 'Parent', handles.axes2);
fn = fspecial('gaussian', [13 13], 1);
setImg(I);
catch me
end
% --- Executes on button press in SaveImage.
function SaveImage_Callback(hObject, eventdata, handles)
% hObject handle to SaveImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
finalImg = getImg;
[filename, foldername] = uiputfile('New Image.jpg');
complete_name = fullfile(foldername, filename);
imwrite(finalImg, complete_name);
% --- Executes on button press in LessBrightness.
function LessBrightness_Callback(hObject, eventdata, handles)
% hObject handle to LessBrightness (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
try
img = getImg;
I = imadd(img,-10);
imshow(I, 'Parent', handles.axes2);
fn = fspecial('gaussian', [13 13], 1);
setImg(I);
catch me
end
function originalImage_Callback(hObject, eventdata, handles)
% hObject handle to originalImage (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,'String') returns contents of originalImage as text
% str2double(get(hObject,'String')) returns contents of originalImage as a double
% --- Executes during object creation, after setting all properties.
function originalImage_CreateFcn(hObject, eventdata, handles)
% hObject handle to originalImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function afterfilter_Callback(hObject, eventdata, handles)
% hObject handle to afterfilter (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,'String') returns contents of afterfilter as text
% str2double(get(hObject,'String')) returns contents of afterfilter as a double
% --- Executes during object creation, after setting all properties.
function afterfilter_CreateFcn(hObject, eventdata, handles)
% hObject handle to afterfilter (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in MoreSmooth.
function MoreSmooth_Callback(hObject, eventdata, handles)
% hObject handle to MoreSmooth (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
try
img = getImg;
I2 = imadd(img,10);
fn = fspecial('gaussian', [13 13], 1);
I = imfilter(I2,fn);
imshow(I, 'Parent', handles.axes2);
setImg(I);
catch me
end
% --- Executes on button press in SharpFilter.
function SharpFilter_Callback(hObject, eventdata, handles)
% hObject handle to SharpFilter (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
try
img = getImg;
I2 = imadd(img,-10);
fn = fspecial('gaussian', [13 13], 1);
I = imfilter(I2,fn);
imshow(I, 'Parent', handles.axes2);
setImg(I);
catch me
end
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, 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
% --- Executes on button press in LessSharpButton.
function LessSharpButton_Callback(hObject, eventdata, handles)
% hObject handle to LessSharpButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in MoreSharpButton.
function MoreSharpButton_Callback(hObject, eventdata, handles)
% hObject handle to MoreSharpButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
  1 comentario
Geoff Hayes
Geoff Hayes el 13 de En. de 2022
@Eiman Hakimy - how are the sharpening buttons different from the brightness buttons? Are you unsure of the algorithms needed or is it something else?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Graphics Objects en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by