function varargout = hights(varargin)
% HIGHTS M-file for hights.fig
% HIGHTS, by itself, creates a new HIGHTS or raises the existing
% singleton*.
%
% H = HIGHTS returns the handle to a new HIGHTS or the handle to
% the existing singleton*.
%
% HIGHTS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in HIGHTS.M with the given input arguments.
%
% HIGHTS('Property','Value',...) creates a new HIGHTS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before hights_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to hights_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help hights
% Last Modified by GUIDE v2.5 23-May-2009 12:29:19
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @hights_OpeningFcn, ...
'gui_OutputFcn', @hights_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 hights is made visible.
function hights_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 hights (see VARARGIN)
% Choose default command line output for hights
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes hights wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = hights_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 im
[filename,pathname]=uigetfile({'*.jpg';'*.bmp''*.gif'},'选择图片');
str=[pathname filename];
im=imread(str);
axes(handles.axes1);
imshow(im)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close
% --------------------------------------------------------------------
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to uipanel1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im
str1=get(hObject,'string');
hold on
axes(handles.axes2);
switch str1
case '原图'
imshow(im)
case '亮度替换'
YUV=rgb2ycbcr(im);
% 将RGB颜色空间转变为YUV(ycbcr空间);
[m n L]=size(YUV);
X=reshape(YUV(:,:,1),m*n,1);
X=double(X)./255;
% 将亮度值“归一化”;
STR=size(X);
for t=1:STR
if X(t)>0.66 && X(t)<0.9215
% X(t)=fun(X(t));
X(t)=fun(X(t));
end
end
% 找到亮度值大于170(处理之后为0.666),认为为高光区域,用处理后的亮度值替换;
X=X*255;
X=round(X);% 取整
YUV(:,:,1)=reshape(X,m,n);
RGB=ycbcr2rgb(YUV);% 换回RGB颜色空间
imshow(RGB);
case '色度修补'
YUV=rgb2ycbcr(im);
% 将RGB颜色空间转变为YUV(ycbcr空间);
[m n L]=size(YUV);
X=reshape(YUV(:,:,1),m*n,1);
U=reshape(YUV(:,:,2),m*n,1);
V=reshape(YUV(:,:,3),m*n,1);
b=max(X);
Y=X;
% ****************************************************************
%------------------求合适的UV值---------------------
Y1=find(X>120&X<150);
s0=length(Y1);
for t=1:s0
U1(t)=U(Y1(t));
end
a1=mean(U1);
a10=round(a1);
for t=1:s0
V1(t)=V(Y1(t));
end
b1=mean(V1);
b10=round(b1);
Y2=find(X>150&X<170);
s1=length(Y2);
for t=1:s1
U2(t)=U(Y2(t));
end
a2=mean(U2);
a20=round(a2);
for t=1:s1
V2(t)=V(Y2(t));
end
b2=mean(V2);
b20=round(b2);
%********************************************************************
%-------------将合适的UV值带入-----------------------
Y3=find(X>170&X<200);
s2=length(Y3);
for t=1:s2
U(Y3(t))=a10;
end
for t=1:s2
V(Y3(t))=b10;
end
Y4=find(X>200&X<b);
s3=length(Y4);
for t=1:s3
U(Y4(t))=a20;
end
for t=1:s3
V(Y4(t))=b20;
end
% **********************************************************************
X=double(X)./255;
% 将亮度值“归一化”;
STR=size(X);
for t=1:STR
if X(t)>0.666 && X(t)<0.9215
% X(t)=fun(X(t));
X(t)=fun(X(t));
end
end
% 找到亮度值大于170(处理之后为0.666),认为为高光区域,用处理后的亮度值替换;
X=X*255;
X=round(X);% 取整
YUV(:,:,1)=reshape(X,m,n);
YUV(:,:,2)=reshape(U,m,n);
YUV(:,:,3)=reshape(V,m,n);
RGB=ycbcr2rgb(YUV);% 换回RGB颜色空间
imshow(RGB);
case '交互操作'
YUV=rgb2ycbcr(im);
% 将RGB颜色空间转变为YUV(ycbcr空间);
[m n L]=size(YUV);
X=reshape(YUV(:,:,1),m*n,1);
[x,y]=ginput(5);
x=round(x);
y=round(y);
for t=1:5
Y2(t)=YUV(y(t),x(t),2);
Y3(t)=YUV(y(t),x(t),3);
end
a=round(mean(Y2));
b=round(mean(Y3));
for i=1:m
for j=1:n
if YUV(i,j,1)>170
YUV(i,j,2)=a;
YUV(i,j,3)=b;
end
end
end
X=double(X)./255;
% 将亮度值“归一化”;
STR=size(X);
for t=1:STR
if X(t)>0.666 && X(t)<0.9215
% X(t)=fun(X(t));
X(t)=fun(X(t));
end
end
% 找到亮度值大于170(处理之后为0.666),认为为高光区域,用处理后的亮度值替换;
X=X*255;
X=round(X);% 取整
YUV(:,:,1)=reshape(X,m,n);
RGB=ycbcr2rgb(YUV);% 换回RGB颜色空间
figure,imshow(RGB);
end
% --------------------------------------------------------------------
function file_1_Callback(hObject, eventdata, handles)
% hObject handle to file_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function open_2_Callback(hObject, eventdata, handles)
% hObject handle to open_2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
pushbutton1_Callback(hObject, eventdata, handles)
% --------------------------------------------------------------------
function close_3_Callback(hObject, eventdata, handles)
% hObject handle to close_3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close
评论20