HSV陰影消除及YUV陰影消除對比代碼及使用說明_第1頁
HSV陰影消除及YUV陰影消除對比代碼及使用說明_第2頁
HSV陰影消除及YUV陰影消除對比代碼及使用說明_第3頁
HSV陰影消除及YUV陰影消除對比代碼及使用說明_第4頁
HSV陰影消除及YUV陰影消除對比代碼及使用說明_第5頁
已閱讀5頁,還剩10頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、精品好資料學習推薦基于matlab 的HSV陰影消除代碼,畢設所用,用完貢獻先給代碼后有說明function varargout = untitled111111(varargin)% UNTITLED111111 M-file for untitled111111.fig% UNTITLED111111, by itself, creates a new UNTITLED111111 or raises the existing% singleton*.% H = UNTITLED111111 returns the handle to a new UNTITLED111111 or the

2、 handle to% the existing singleton*.% UNTITLED111111(CALLBACK,hObject,eventData,handles,.) calls the local% function named CALLBACK in UNTITLED111111.M with the given input arguments.% UNTITLED111111(Property,Value,.) creates a new UNTITLED111111 or raises the% existing singleton*. Starting from the

3、 left, property value pairs are% applied to the GUI before untitled111111_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to untitled111111_OpeningFcn via varargin.% *See GUI Options on GUIDEs Tools menu. Choose GUI allo

4、ws only one% instance to run (singleton).% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help untitled111111% 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

5、_Singleton, gui_Singleton, . gui_OpeningFcn, untitled111111_OpeningFcn, . gui_OutputFcn, untitled111111_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

6、 gui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT% - Executes just before untitled111111 is made visible.function untitled111111_OpeningFcn(hObject, , handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to b

7、e defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to untitled111111 (see VARARGIN)% Choose default command line output for untitled111111handles.output = hObject;% Update handles structureguidata(hObject, handles);% U

8、IWAIT makes untitled111111 wait for user response (see UIRESUME)% uiwait(handles.figure1);% - Outputs from this function are returned to the command line.function varargout = untitled111111_OutputFcn(, , handles) % varargout cell array for returning output args (see VARARGOUT);% hObject handle to fi

9、gure% 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 structurevarargout1 = handles.output;% - Executes on button press in pushbutton1.function pushbutton1_Callback(, , )handles

10、=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,iw,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)% %關閉初始化窗口 % 試試不用轉

11、置直接用u來進行median(t);tmp=median(t); % 對t數(shù)組各列取均值global mean;mean=reshape(tmp,ih,iw,id); % 將n幀均值圖像恢復成h*w*d的圖像矩陣,得到背景subplot(2,2,1),imshow(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

12、,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 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(o

13、k);title(提取前景圖像); % %第三幅前景圖count2=count2*1.25;e1=num2str(count2);sc=共,e1;sc=sc,點;set(handles.text16,String,sc);g=rgb2hsv(mean); % 將背景圖像由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

14、(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(ai,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),imsho

15、w(BHuidu);title(提取前景圖像); % %第三幅前景圖%figure,imshow(QHuidu);%figure,imshow(BHuidu);Yyu=double(QHuidu(:,:,1)-double(BHuidu(:,:,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);Y

16、UVhecheng=Uyu;Q=(UVErzhihua=1)&(YErzhihua=1); %Y分量和UV分量的圖像合成YUVhecheng(Q)=1;Q=(UVErzhihua=0)|(YErzhihua=0);YUVhecheng(Q)=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

17、(YUV陰影消除);% 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)% - Executes on button press in pushbutton3.function pushbutton3_Callback(, , )clc;close all;close(gcf);clear;% hObject ha

18、ndle to pushbutton3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)ai% - Executes on button press in pushbutton4.function pushbutton4_Callback(, , )h1=figure(toolbar,none,name,Shadow Removal); % 讀取受損圖像FileName,P

19、athName=uigetfile( *.avi,avi (*.avi);*.*,All Files (*.*),Open video sequence );if isequal(FileName,PathName,0,0) return;else pic_path=fullfile(PathName,FileName); global mov; mov=aviread(pic_path);endn=size(mov,2); %計算視頻的幀數(shù)(試試用這個代替下面的)%n=100; % 讀取視頻幀數(shù)global s;s=1; % 起始為1global e;e=n; % 結束為n%global f

20、n;%fn=11; % hObject handle to pushbutton4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles 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

21、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,

22、 , )% 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,Back

23、groundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);endfunction edit2_Callback(hObject, , 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)% Hi

24、nts: get(hObject,String) returns contents of edit2 as text% str2double(get(hObject,String) returns contents of edit2 as a doubleinput = str2num(get(hObject,String);if (isempty(input) set(hObject,String,11)endguidata(hObject, handles)% - Executes during object creation, after setting all properties.f

25、unction edit2_CreateFcn(hObject, , )% hObject handle to edit2 (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

26、 ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);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

27、version of MATLAB% handles structure with handles and user data (see GUIDATA)global fn;global e;e=num2str(e);sc=共,e;sc=sc,幀;%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 hand

28、le to edit3 (see GCBO)% eventdata 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,1)endguidata(hObject, handles)% Hints: get(hObject,String) returns contents of

29、 edit3 as text% str2double(get(hObject,String) returns contents of edit3 as a double% - Executes during object creation, 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 e

30、mpty - 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 edit4_Callback(hO

31、bject, , handles)% hObject handle to edit4 (see GCBO)% eventdata 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,1)endguidata(hObject, handles)% Hints: get(hObj

32、ect,String) returns contents of edit4 as text% str2double(get(hObject,String) returns contents of edit4 as a double% - Executes during object creation, after setting all properties.function edit4_CreateFcn(hObject, , )% hObject handle to edit4 (see GCBO)% eventdata reserved - to be defined in a futu

33、re 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

34、);endfunction edit5_Callback(hObject, , handles)% hObject handle to edit5 (see GCBO)% eventdata 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,2)endguidata(hOb

35、ject, handles)% Hints: get(hObject,String) returns contents of edit5 as text% str2double(get(hObject,String) returns contents of edit5 as a double% - Executes during object creation, after setting all properties.function edit5_CreateFcn(hObject, , )% hObject handle to edit5 (see GCBO)% eventdata res

36、erved - 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) se

37、t(hObject,BackgroundColor,white);endfunction edit6_Callback(hObject, , handles)% hObject handle to edit6 (see GCBO)% eventdata 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(

38、hObject,String,0.32)endguidata(hObject, handles)% Hints: get(hObject,String) returns contents of edit6 as text% str2double(get(hObject,String) returns contents of edit6 as a double% - Executes during object creation, after setting all properties.function edit6_CreateFcn(hObject, , )% hObject handle

39、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

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論