HSV阴影消除及YUV阴影消除对比代码及使用说明_第1页
HSV阴影消除及YUV阴影消除对比代码及使用说明_第2页
HSV阴影消除及YUV阴影消除对比代码及使用说明_第3页
HSV阴影消除及YUV阴影消除对比代码及使用说明_第4页
HSV阴影消除及YUV阴影消除对比代码及使用说明_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精选优质文档-倾情为你奉上基于matlab 的HSV阴影消除代码,毕设所用,用完贡献先给代码 后有说明function varargout = untitled(varargin)% UNTITLED M-file for untitled.fig% UNTITLED, by itself, creates a new UNTITLED or raises the existing% singleton*.% H = UNTITLED returns the handle to a new UNTITLED or the handle to% the existing singleton*.%

2、 UNTITLED(CALLBACK,hObject,eventData,handles,.) calls the local% function named CALLBACK in UNTITLED.M with the given input arguments.% UNTITLED(Property,Value,.) creates a new UNTITLED or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before un

3、titled_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to untitled_OpeningFcn via varargin.% *See GUI Options on GUIDEs Tools menu. Choose GUI allows only one% instance to run (singleton).% See also: GUIDE, GUIDATA, GUIH

4、ANDLES% Edit the above text to modify the response to help untitled% Last Modified by GUIDE v2.5 31-Mar-2014 09:39:29% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct(gui_Name, mfilename, . gui_Singleton, gui_Singleton, . gui_OpeningFcn, untitled_OpeningFcn, . gui_OutputF

5、cn, untitled_OutputFcn, . gui_LayoutFcn, , . gui_Callback, );if nargin & ischar(varargin1) gui_State.gui_Callback = str2func(varargin1);endif nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:);else gui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT% - Executes j

6、ust before untitled is made visible.function untitled_OpeningFcn(hObject, , 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)% va

7、rargin command line arguments to untitled (see VARARGIN)% Choose default command line output for untitledhandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes untitled wait for user response (see UIRESUME)% uiwait(handles.figure1);% - Outputs from this function

8、are returned to the command line.function varargout = untitled_OutputFcn(, , 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 GUIDA

9、TA)% Get default command line output from handles structurevarargout1 = handles.output;% - Executes on button press in pushbutton1.function pushbutton1_Callback(, , )handles=guihandles();global s;global e;global fn;global mov;for i=s:e mov_gray(i).image=mov(i).cdata; % mov_gray(i).image为第i帧图像endih,i

10、w,id=size(mov_gray(1).image); % 取得视频帧的大小% 计算1到第n帧的各个像素的均值for i=s:e u=mov_gray(i).image; h=u(:); % 转置 t(i,:)=h(:); % median(t)是对列进行取均值的end%close(figure(gcf)% %关闭初始化窗口 % 试试不用转置直接用u来进行median(t);tmp=median(t); % 对t数组各列取均值global mean;mean=reshape(tmp,ih,iw,id); % 将n帧均值图像恢复成h*w*d的图像矩阵,得到背景subplot(2,2,1),i

11、mshow(uint8(mean);title(背景图像); %第一幅 背景图 %取第fn帧作为对象subplot(2,2,2),imshow(uint8(mov_gray(fn).image);title(目标图像); %第二幅 完整图像global ok; ok=mean; %ok-背景%tmp(1:3)=0;di=15;th=ones(1,1,3)*di; % 预设阀值diff=double(ok)-double(mov_gray(fn).image); % 计算第fn帧图像与背景的差值diff1=abs(diff);count2=0;for ai=1:ih for bi=1:iw if

12、 abs(diff(ai,bi,1:3)=th(1,1,:) ok(ai,bi,1:3)=mov_gray(fn).image(ai,bi,1:3); count2=count2+1; else ok(ai,bi,1:3)=0; diff1(ai,bi,1:3)=0; end endend%subplot(2,2,3),imshow(uint8(ok);title(提取前景图像); % %第三幅 前景图count2=count2*1.25;e1=num2str(count2);sc=共,e1;sc=sc,点;set(handles.text16,String,sc);g=rgb2hsv(mea

13、n); % 将背景图像由RGB格式转为HSV格式g1=rgb2hsv(ok); % 将前景图像由RGB格式转为HSV格式% 阀值分割global TH1;global TH2;global TS;global TV;count4=0;for ci=1:ih for di=1:iw if (g1(ci,di,3)/g(ci,di,3)TS|abs(g1(ci,di,1)-g(ci,di,1)TH2&g1(ci,di,1)=th(1,1,:)% ok(ai,bi,1:3)=mov_gray(fn).image(ai,bi,1:3);% else% ok(ai,bi,1:3)=0;% diff1(a

14、i,bi,1:3)=0;% end% end%end%subplot(2,2,3),imshow(uint8(ok);title(提取前景图像); % %第三幅 前景图QHuidu=rgb2ycbcr(Qianjing); %RGB颜色空间转换到YUV颜色空间BHuidu=rgb2ycbcr(Beijing);%subplot(2,2,4),imshow(BHuidu);title(提取前景图像); % %第三幅 前景图%figure,imshow(QHuidu);%figure,imshow(BHuidu);Yyu=double(QHuidu(:,:,1)-double(BHuidu(:,:

15、,1); %Y分量的差分YErzhihua=Yyu;Q= abs(Yyu)10; %Y分量差分图像的二值化YErzhihua(Q)=1;Q= abs(Yyu)10; %UV分量的图像的合成 UVErzhihua(Q)=1;Q= abs(Uyu)+abs(Vyu)=10;UVErzhihua(Q)=0;%figure,imshow(UVErzhihua);YUVhecheng=Uyu;Q=(UVErzhihua=1)&(YErzhihua=1); %Y分量和UV分量的图像合成YUVhecheng(Q)=1;Q=(UVErzhihua=0)|(YErzhihua=0);YUVhecheng(Q)=

16、0;YUV=YUVhecheng;for ci=1:ih for di=1:iw if YUV(ci,di)=1 ok(ci,di,1:3)=mov_gray(fn).image(ci,di,1:3); else ok(ci,di,1:3)=mean(ci,di,1:3); end endendsubplot(2,2,4),imshow(ok);title(YUV阴影消除);% hObject handle to pushbutton2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% h

17、andles structure with handles and user data (see GUIDATA)% - Executes on button press in pushbutton3.function pushbutton3_Callback(, , )clc;close all;close(gcf);clear;% hObject handle to pushbutton3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with

18、handles and user data (see GUIDATA)ai% - Executes on button press in pushbutton4.function pushbutton4_Callback(, , )h1=figure(toolbar,none,name,Shadow Removal); % 读取受损图像FileName,PathName=uigetfile( *.avi,avi (*.avi);*.*,All Files (*.*),Open video sequence );if isequal(FileName,PathName,0,0) return;e

19、lse pic_path=fullfile(PathName,FileName); global mov; mov=aviread(pic_path);endn=size(mov,2); %计算视频的帧数(试试用这个代替下面的)%n=100; % 读取视频帧数global s;s=1; % 起始为1global e;e=n; % 结束为n%global fn;%fn=11; % hObject handle to pushbutton4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% h

20、andles structure with handles and user data (see GUIDATA)function edit1_Callback(, , )% 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 edi

21、t1 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, , )% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty

22、 - 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);endfunction edit2_Callback(hObjec

23、t, , handles)% hObject handle to edit2 (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 edit2 as text% str2double(get(hObject,String) returns contents of edit2 as a

24、 doubleinput = str2num(get(hObject,String);if (isempty(input) set(hObject,String,11)endguidata(hObject, handles) % - Executes during object creation, after setting all properties.function edit2_CreateFcn(hObject, , )% hObject handle to edit2 (see GCBO)% eventdata reserved - to be defined in a future

25、 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);

26、end% - Executes on button press in pushbutton5.function pushbutton5_Callback(, , handles)% hObject handle to pushbutton5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global fn;global e;e=num2str(e);sc=共,e;sc=s

27、c,帧;%a = get(handles.edit1,String);fn = str2double(get(handles.edit2,String);set(handles.text15,String,sc);e=str2double(e);function edit3_Callback(hObject, , handles)% hObject handle to edit3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles

28、 and user data (see GUIDATA)input = str2num(get(hObject,String);if (isempty(input) set(hObject,String,1)endguidata(hObject, handles)% Hints: get(hObject,String) returns contents of edit3 as text% str2double(get(hObject,String) returns contents of edit3 as a double% - Executes during object creation,

29、 after setting all properties.function edit3_CreateFcn(hObject, , )% hObject handle to edit3 (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 Win

30、dows.% See ISPC and COMPUTER.if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);endfunction edit4_Callback(hObject, , handles)% hObject handle to edit4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB%

31、 handles structure with handles and user data (see GUIDATA)input = str2num(get(hObject,String);if (isempty(input) set(hObject,String,1)endguidata(hObject, handles)% Hints: get(hObject,String) returns contents of edit4 as text% str2double(get(hObject,String) returns contents of edit4 as a double% - E

32、xecutes during object creation, after setting all properties.function edit4_CreateFcn(hObject, , )% hObject handle to edit4 (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

33、 have a white background on Windows.% See ISPC and COMPUTER.if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);endfunction edit5_Callback(hObject, , handles)% hObject handle to edit5 (see GCBO)% eventdata reserved - to be defined

34、 in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)input = str2num(get(hObject,String);if (isempty(input) set(hObject,String,2)endguidata(hObject, handles)% Hints: get(hObject,String) returns contents of edit5 as text% str2double(get(hObject,String) returns con

35、tents of edit5 as a double% - Executes during object creation, after setting all properties.function edit5_CreateFcn(hObject, , )% hObject handle to edit5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns call

36、ed% 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);endfunction edit6_Callback(hObject, , handles)% hObject handle to edit6 (see GCBO)% eve

37、ntdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)input = str2num(get(hObject,String);if (isempty(input) set(hObject,String,0.32)endguidata(hObject, handles)% Hints: get(hObject,String) returns contents of edit6 as text% str2doub

38、le(get(hObject,String) returns contents of edit6 as a double% - Executes during object creation, after setting all properties.function edit6_CreateFcn(hObject, , )% hObject handle to edit6 (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 push

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论