彩色圖像空間轉換代碼_第1頁
彩色圖像空間轉換代碼_第2頁
彩色圖像空間轉換代碼_第3頁
彩色圖像空間轉換代碼_第4頁
彩色圖像空間轉換代碼_第5頁
已閱讀5頁,還剩3頁未讀 繼續免費閱讀

下載本文檔

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

文檔簡介

1、精選優質文檔-傾情為你奉上圖像篡改檢測Matlab源代碼說明(1) 彩色圖像空間轉換代碼(RGB空間轉換為YUV空間)clc;clear all;close all;img = imread('3.jpg');%figure;imshow(img);title('原圖');img_5=img;img_ycbcr = rgb2ycbcr(img); % rgb->yuvfigure;subplot(121);imshow(img);title('原始圖像');subplot(122);imshow(img_ycbcr);title('

2、YUV空間圖');圖1 彩色圖像空間轉換(2)圖像分塊(分為16*16子塊)row,col,i=size(img_ycbcr);%對圖像進行擴展row_expand=ceil(row/16)*16; %行數上取整再乘16,及擴展成16的倍數if mod(row,16)=0 %行數不是16的倍數,用最后一行進行擴展 for i=row:row_expand img_ycbcr(i,:,:)=img_ycbcr(row,:,:); endendcol_expand=ceil(col/16)*16; %列數上取整if mod(col,16)=0 %列數不是16的倍數,用最后一列進行擴展 fo

3、r j=col:col_expand img_ycbcr(:,j,:)=img_ycbcr(:,col,:); endend(3)對各個分量(Y,Cr,Cb)進行離散余弦變換量化%對各分量進行4:2:0采樣Y=img_ycbcr(:,:,1); %Y分量figure;subplot(231);imshow(Y);title('原Y分量');Cb=img_ycbcr(:,:,2); %Cb分量Cr=img_ycbcr(:,:,3); %Cr分量 Cb = zeros(row_expand/2,col_expand/2); Cr = zeros(row_expand/2,col_e

4、xpand/2);for i=1:row_expand/2 for j=1:2:col_expand/2-1 %奇數 Cb(i,j)=double(img_ycbcr(i*2-1,j*2-1,2); Cr(i,j)=double(img_ycbcr(i*2-1,j*2+1,3); endendfor i=1:row_expand/2 %偶數 for j=2:2:col_expand/2 Cb(i,j)=double(img_ycbcr(i*2-1,j*2-2,2); Cr(i,j)=double(img_ycbcr(i*2-1,j*2,3); endendsubplot(232);imshow

5、(uint8(Cb);title('原Cb分量'); %Cb分量subplot(233);imshow(uint8(Cr);title('原Cr分量'); %Cr分量Y_Table=16 11 10 16 24 40 51 61 12 12 14 19 26 58 60 55 14 13 16 24 40 57 69 56 14 17 22 29 51 87 80 62 18 22 37 56 68 109 103 77 24 35 55 64 81 104 113 92 49 64 78 87 103 121 120 101 72 92 95 98 112 1

6、00 103 99;%亮度量化表 CbCr_Table=17, 18, 24, 47, 99, 99, 99, 99; 18, 21, 26, 66, 99, 99, 99, 99; 24, 26, 56, 99, 99, 99, 99, 99; 47, 66, 99 ,99, 99, 99, 99, 99; 99, 99, 99, 99, 99, 99, 99, 99; 99, 99, 99, 99, 99, 99, 99, 99; 99, 99, 99, 99, 99, 99, 99, 99; 99, 99, 99, 99, 99, 99, 99, 99;%色差量化表Qua_Factor=

7、0.2;%量化因子%對Y分量進行處理Qua_Matrix=Qua_Factor*Y_Table; %Y量化矩陣Y = blkproc(Y,8 8,'dct2(x)'); %DCT變換Y = blkproc(Y,8 8,'round(x./P1)',Qua_Matrix); %量化Y = blkproc(Y,8 8,'x.*P1',Qua_Matrix);%反量化Y= blkproc(Y,8 8,'idct2(x)');%反DCT變換subplot(234);imshow(uint8(Y);title('Y分量量化后'

8、;);%對Cb分量進行處理Qua_Matrixcc=0.2*CbCr_Table; % Cb質量因子選取為5,并不采用Qua_Factor的數值Cb = blkproc(Cb,8 8,'dct2(x)'); %DCT變換Cb = blkproc(Cb,8 8,'round(x./P1)',Qua_Matrixcc); %量化Cb = blkproc(Cb,8 8,'x.*P1',Qua_Matrixcc);%反量化Cb = blkproc(Cb,8 8,'idct2(x)');%反DCT變換subplot(235);imshow(

9、uint8(Cb);title('Cb分量量化后'); %對Cr分量進行處理Qua_Matrixcc=0.2*CbCr_Table; %Cr質量因子選取為5,并不采用Qua_Factor的數值Cr = blkproc(Cr,8 8,'dct2(x)'); %DCT變換Cr = blkproc(Cr,8 8,'round(x./P1)',Qua_Matrixcc); %量化Cr = blkproc(Cr,8 8,'x.*P1',Qua_Matrixcc);%反量化Cr = blkproc(Cr,8 8,'idct2(x)&#

10、39;);%反DCT變換subplot(236);imshow(uint8(Cr);title('Cr分量量化后');圖2 各個分量量化圖像(4)對各分量(Y,Cr,Cb)進行二值化處理 %對Y分量處理%差分處理dh_Y = diff(Y,2);%水平差分dvt_Y = diff(Y); %縱向差分dv_Y= dvt_Y' %顯示功率譜密度fs=1000;n=0:1/fs:1;nfft=1024;window=blackman(100);noverlap=20;range='half'pxx1,f=pwelch(dh_Y,window,noverlap,

11、nfft,fs,range);pxx2,f=pwelch(dvt_Y,window,noverlap,nfft,fs,range);plot_pxx1=10*log10(pxx1);plot_pxx2=10*log10(pxx2); figure,subplot(121);plot(f,plot_pxx1);title('水平功率譜密度');subplot(122);plot(f,plot_pxx2);title('垂直功率譜密度'); %計算功率譜密度dh1_Y= blkproc(dh_Y,8 8,'welch'); %水平方向差分圖像的區域功

12、率譜密度dv1_Y= blkproc(dv_Y,8 8,'welch'); %垂直方向差分圖像的區域功率譜密度b1_Y= blkproc(dh1_Y,513 1,'sum(x(:)');%水平方向差分圖像的區域功率譜密度總和b2_Y= blkproc(dv1_Y,513 1,'sum(x(:)');%垂直方向差分圖像的區域功率譜密度總和b_Y=b1_Y+b2_Y'%整幅圖像的區域功率譜密度總和 for i=1:size(b_Y,1) for j=1:size(b_Y,2) B_Y(i,j)=exp(log(sum(b_Y(i,j)+1)/

13、(sum(b_Y(i,j)+1);%整幅圖像塊效應評價 endend %二值化處理T=exp(1.5)*sum(sum(B_Y)/(row_expand/8)*(col_expand/8);%閾值c_Y=zeros(size(Y);for i=1:size(Y,1) for j=1:size(Y,2) if b_Y(ceil(i/8),ceil(j/8)>T c_Y(i,j)=1; end endendfigure;subplot(121);imshow(int8(b_Y); title('Y分量離散余弦系數圖');subplot(122);imshow(c_Y); ti

14、tle('Y分量二值圖像');圖3 Y分量離散余弦變換二值化圖像圖4 Cb分量離散余弦變換二值化圖像圖5 Cr分量離散余弦變換二值化圖像(5) 提取各個子圖特征function featureVec = GetBlockFeature(Block)featureVec=zeros(1,7); %特征數組,共設置7個特征R = Block(:,:, 1);G = Block(:,:, 2);B = Block(:,:, 3); %cl,c2, c3三個特征值featureVec(1)=mean2(R(:);featureVec(2)=mean2(G(:);featureVec(3

15、)=mean2(B(:); %c4.5.6.7四個特征值,Y通道公式Y = im2double(0.299 * R + 0.587 * G + 0.114 * B); %塊內所有像素灰度之和totalGray = sum(Y(:); %c4sum_partI= sum(sum(Y(1 : 8,:);featureVec(4) = sum_partI / totalGray; %c5sum_partI = sum(sum(Y(:,1 : 8);featureVec(5) = sum_partI/ totalGray; %c6sumPart11 = 0.0;for r = 1 : 16 for c

16、 = r : 16 sumPart1 = sumPart11 + Y(r, c); endendfeatureVec(6)=sumPart1/totalGray; %c7sumPart11 = 0.0;for r = 1 : 16 for c = 1 : (16 - r + 1) sumPart1 = sumPart11 + Y(r, c); endendfeatureVec(7)= sumPart1 / totalGray;return;(6) 特征排序FeatureVecThresh =2.5,1.5,3.0,0.006,0.005,0.005,0.005;BlockDistThresh

17、= 10;BlockPairsNum = NumBlocks - 1 ;ShiftVectors = zeros(1,2);candidateSimilarPairs.indices = zeros(1,2);candidateSimilarPairs.frequence(1) = 0;features, indices = sortrows(Blocks.features);vi = 0;for i = 1 : NumBlocks - 1 ind1 = indices(i); ind2 = indices(i + 1); deltaCoord = Blocks.topLeft(ind1,:)

18、-Blocks.topLeft(ind2,:); deltaFeature = Blocks.features(ind1,:)-Blocks.features(ind2,:); pixelDist = norm(deltaCoord); %向景取模 if (pixelDist>BlockDistThresh) && (sum(abs(deltaFeature)<FeatureVecThresh) = 7) vi = vi + 1; candidateSimilarPairs.indices(vi, :)=ind1 ind2; ShiftVectors(vi,:) =

19、 Blocks.topLeft(ind1,:)-Blocks.topLeft(ind2,:); endend(7) 查找并刪除重復圖像塊SimilarPairs.indices=zeros(1,2);pairs.vector1=ShiftVectors(1,:); %第一行pairs.freq(1)=1;ind=1;for i=2:size(ShiftVectors,1); vec=ShiftVectors(i,:); isExist=false; for j=1:ind if norm(vec-pairs.vectorj)<2 pairs.freq(j)=pairs.freq(j)+1; isExist=true; break; end end if isExist ind=ind+1; pairs.vectorind=vec; pairs.freq(ind)=1; endendmax_freq, ma

溫馨提示

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

評論

0/150

提交評論