我正在尝试从Mathworks网站实现盲去卷积算法示例,并且在进行边缘检测时我遇到了问题,因为您无法对RGB照片使用边缘检测功能。所以我将照片转换为YUV,但在此之后我不知道我应该以什么顺序进行处理,我甚至不知道我是否使用了正确的方法。
我对所有三个(y,u,v)应用了edge()函数,然后我使用YUV到RGB方法再次组合它们。它不起作用,我无法获得最终的重量值。
我的代码如下,示例链接位于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')
答案 0 :(得分:4)
我不会在这里进入deconvblind
去模糊,但让我向您展示彩色图像的边缘检测是如何工作的。
% load an image
I = imread('peppers.png');
% note that this is a RGB image.
e = edge(I, 'sobel');
会失败,因为在第三维是颜色通道的意义上,边需要2D图像,RGB或YUV图像是3D。
有几种方法可以解决这个问题。一种是使用
将图像转换为灰度gray = rgb2gray(I);
然后可以将其传递到边缘,以根据&lt; gray
&#39;中的灰度级强度返回边缘。
e = edge(gray,'sobel'); % also try with different thresholds for sobel.
如果您真的对每个频道中的边缘信息感兴趣,您可以简单地将各个频道分别传入边缘。例如,
eRed = edge(I(:,:,1), 'sobel'); % edges only in the I(:,:,1): red channel.
eGreen = edge(I(:,:,2), 'sobel');
eBlue = edge(I(:,:,3), 'sobel');
然后根据每个eRed
,eGreen
和eBlue
的外观,你可以使用逻辑&#39;或&#39;进行组合,以便如果任何通道独立地认为它是边缘,则结果是边缘。
eCombined = eRed | eGreen | eBlue;
你原来做的可能是无意的,因为YUV色彩空间会扭曲边缘感。 R平面中的边缘可能不是Y,U或V平面中的边缘,因此您需要确保使用正确的颜色空间来检测边缘,以便您可以在之后将它们组合,如图所示早期使用RGB色彩空间。
答案 1 :(得分:0)
最终的代码形式如下,
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);
eRed = edge(Img(:,:,1), 'sobel');
eGreen = edge(Img(:,:,2), 'sobel');
eBlue = edge(Img(:,:,3), 'sobel');
WEIGHT = eRed | eGreen | eBlue;
se1 = strel('disk',1);
se2 = strel('line',13,45);
WEIGHT = ~imdilate(WEIGHT,[se1 se2]);
WEIGHT = padarray(WEIGHT(2:end-1,2:end-1),[1 1]);
figure
imshow(WEIGHT)
title('Weight Array')
P1 = P;
P1(find(P1 < 0.01))= 0;
WEIGHT2 = repmat(WEIGHT,[1 1 3]);
WEIGHT3 = im2double(WEIGHT2);
[J2 P2] = deconvblind(Blurred,P1,50,[],WEIGHT3);
figure, imshow(J2)
title('Newly Deblurred Image');
figure, imshow(P2,[],'InitialMagnification','fit')
title('Newly Reconstructed PSF')
我无法发布图片。所以我给出了输出的链接。最后一次输出,新恢复,有问题,因为我在照片的标题上表示。我猜,仍然在那里&#39 ; sa数据类型问题。 输出链接http://imgur.com/a/dDF2N