【发布时间】:2016-05-08 08:18:11
【问题描述】:
我正在尝试实现 Mathworks 网站上的盲反卷积算法示例,但在进行边缘检测时我遇到了问题,因为您不能对 RGB 照片使用边缘检测功能。所以我将照片转换为 YUV,但在此之后我不知道我应该按什么顺序进行处理,我什至不知道我是否使用了正确的方法。
我为所有三个 (y,u,v) 应用了 edge() 函数,然后我使用 YUV 到 RGB 方法再次组合它们。没用,我无法获得最终的 WEIGHT 值。
我的代码如下,示例链接位于http://www.mathworks.com/help/images/deblurring-with-the-blind-deconvolution-algorithm.html。
Img = imread('image.tif');
PSF = fspecial('motion',13,45);
Blurred = imfilter(Img,PSF,'circ','conv');
INITPSF = ones(size(PSF));
[J P] = deconvblind(Blurred,INITPSF,30);
% RGB to YUV
R=Img(:,:,1); G=Img(:,:,2); B=Img(:,:,3);
Y=round((R+2*G+B)/4);
U=R-G;
V=B-G;
% finding edges for Y,U,V
WEIGHT1 = edge(Y,'sobel',.28);
se1 = strel('disk',1);
se2 = strel('line',13,45);
WEIGHT1 = ~imdilate(WEIGHT1,[se1 se2]);
WEIGHT1 = padarray(WEIGHT1(2:end-1,2:end-1),[1 1]);
WEIGHT2 = edge(U,'sobel',.28);
se1 = strel('disk',1);
se2 = strel('line',13,45);
WEIGHT2 = ~imdilate(WEIGHT2,[se1 se2]);
WEIGHT2 = padarray(WEIGHT2(2:end-1,2:end-1),[1 1]);
WEIGHT3 = edge(V,'sobel',.28);
se1 = strel('disk',1);
se2 = strel('line',13,45);
WEIGHT3 = ~imdilate(WEIGHT3,[se1 se2]);
WEIGHT3 = padarray(WEIGHT3(2:end-1,2:end-1),[1 1]);
% YUV to RGB again
G=round((WEIGHT1-(WEIGHT2+WEIGHT3)/4));
R=WEIGHT2+G;
B=WEIGHT3+G;
WEIGHT(:,:,1)=G; WEIGHT(:,:,2)=R; WEIGHT(:,:,3)=B;
P1 = P;
P1(find(P1 < 0.01))= 0;
[J2 P2] = deconvblind(Blurred,P1,50,[],double(WEIGHT));
figure, imshow(J2)
title('Newly Deblurred Image');
figure, imshow(P2,[],'InitialMagnification','fit')
title('Newly Reconstructed PSF')
【问题讨论】:
标签: matlab image-processing edge-detection