function varargout = image_enhance(varargin)
% IMAGE_ENHANCE MATLAB code for image_enhance.fig
% IMAGE_ENHANCE, by itself, creates a new IMAGE_ENHANCE or raises the existing
% singleton*.
%
% H = IMAGE_ENHANCE returns the handle to a new IMAGE_ENHANCE or the handle to
% the existing singleton*.
%
% IMAGE_ENHANCE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IMAGE_ENHANCE.M with the given input arguments.
%
% IMAGE_ENHANCE('Property','Value',...) creates a new IMAGE_ENHANCE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before image_enhance_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to image_enhance_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 image_enhance
% Last Modified by GUIDE v2.5 09-May-2020 09:32:40
% Begin initialization code - DO NOT EDIT
%%%初始化
clc;
global original;
original = imread('imageMoon.jpg');
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @image_enhance_OpeningFcn, ...
'gui_OutputFcn', @image_enhance_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
% --- Executes just before image_enhance is made visible.
function image_enhance_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 image_enhance (see VARARGIN)
% Choose default command line output for image_enhance
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes image_enhance wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = image_enhance_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, 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)
global original;
axes(handles.axes1);
% 取整张图的三维尺寸
[m,n,l] = size(original);
% 通过判断对象类型来决定是否转化为灰度图
if l>1
original = rgb2gray(original);
end
imshow(original)
numb=get(handles.popupmenu1,'value');
% BW=edge(I,'sobel',thresh,direction)
% 根据指定的敏感阈值thresh用Sobel算子对图像进行边缘检测,
% edge函数忽略了所有小于阈值的边缘,如果没有指定阈值thresh或为空,函数自动选择参数值,
% direction指定Sobel算子边缘检测的方向,其参数值为'horizontal','vertical'或'both'(默认)。
% [BW,thresh]=edge(I,'sobel');??
% %返回当前Sobel算子边缘检测的阈值
axes(handles.axes3);
switch numb
case 1%
m = 255;
H = histeq(original,m);
imshow(H)
case 2%
new = StretchFunc(original, 0, 50, 0, 150 );
imshow(new)
case 3%
I=mat2gray(original); %对数变换不支持uint8类型的数据,将一个矩阵归一化为灰度图像的数据格式
new =log(I+1.2);
imshow(new)
case 4%
J=imcomplement(original);
imshow(J)
case 5%
transformed = LinearTransformFunc(original, 1, 150);
imshow(transformed)
case 6%
%%%%%同态滤波
I3=homo_filter(original);
imshow(I3,[]);
end
function LIST_SELECT_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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 edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 [ new ] = StretchFunc(original, x1, y1, x2, y2 )
% 分段线性变换
new = original;
[w,h,l]=size(new);
% w = size(new, 1);
% h = size(new, 2);
k1 = y1 / x1;
dk1 = (y2 - y1) / (x2 - x1);
dk2 = (255 - y2) / (255 - x2);
for i = 1 : w
for j = 1 : h
x = new(i, j);
if x < x1
new(i, j) = k1 * x;
elseif x < x2
new(i, j) = dk1 * (x - x1) + y1;
else
new(i, j) = dk2 * (x - x2) + y2;
end
end
end
function new = homo_filter(original )
%%%%%同态滤波
I=double(original);
[M,N]=size(I);
rL=0.5;
rH=4.7;%可根据需要效果调整参数
c=2;
d0=10;
I1=log(I+1);%取对数
FI=fft2(I1);%傅里叶变换
n1=floor(M/2);
n2=floor(N/2);
H = ones(M, N);
for i=1:M
for j=1:N
D(i,j)=((i-n1).^2+(j-n2).^2);
H(i,j)=(rH-rL).*(exp(c*(-D(i,j)./(d0^2))))+rL;%高斯同态滤波
end
end
I2=ifft2(H.*FI);%傅里叶逆变换
new=real(exp(I2));
function [ new ] = LinearTransformFunc( original, k, b )
% 线性变换
new = original * k + b;