0

我已经按照教授的解释编写了图像压缩代码。它工作正常,但对于某些图像,它显示以下错误:

**Error using  + 
Matrix dimensions must agree.

Error in idwt2 (line 90)
x = upsconv2(a,{Lo_R,Lo_R},sx,dwtEXTM,shift)+ ... % Approximation.

Error in nw (line 56)
DeCompImg=idwt2(cA1,c,cV1,cD1,'haar');** 

该代码适用于少数图像,并显示少数图像的上述错误。我检查了工作区。仅当原始图像尺寸为奇数(255x255)时才会出现此错误。如果图像尺寸是偶数(256x256),则此代码可以正常工作。如何解决此问题without using imresize命令?请帮忙。

我的压缩代码:

%Reading an Image
I=imread('mandrill.jpg');
G=rgb2gray(I);
%Applying Haar Wavelet 

[cA1,cH1,cV1,cD1] = dwt2(G,'haar');

%Applying 2x2 window averaing 

CompImgH=blockproc(cH1, [2 2], @(x) mean(x.data(:)));
CompImgV=blockproc(cV1, [2 2], @(x) mean(x.data(:)));
CompImgD=blockproc(cD1, [2 2], @(x) mean(x.data(:)));

figure(1),
subplot(2,2,1);
imshow(G);
title('Original Image');
subplot(2,2,2);
imshow(CompImgH);
title('Horizontal Component');
subplot(2,2,3);
imshow(CompImgV);
title('Vertical Component');
subplot(2,2,4);
imshow(CompImgD);
title('Diagonal Component');

%DECOMPRESSION


%Inverse process for 2x2 window averaging 
b=CompImgH;
[m,n,colormap]=size(b);

k=1; %Counter for Row and
l=1; %Column replication
%f=input('enter replication factor: ');
f=2; % replication factor

for i=1:m %Loop for reading row and
    for t=1:f %Row replication

        for j=1:n %Loop for reading column and
            for t=1:f %Column replication

                               c(k,l)=b(i,j);
                                l=l+1;
            end
        end
        l=1;
        k=k+1;

    end
end

DeCompImg=idwt2(cA1,c,cV1,cD1,'haar');

DecompressedImage=uint8(DeCompImg);

Orig_Image = im2double(G);%---Convert image to double class
    Reconstructed_Image = im2double(DecompressedImage);%---Convert image to double class
    [M N] = size(Orig_Image);%---Size of Original Image
    err = Orig_Image - Reconstructed_Image;%---Difference between two images
    MSE = (sum(sum(err .* err)))/(M * N);
4

1 回答 1

1

看来在功能idwt2第 90 行的函数中,您正在尝试添加两个不同大小的数组。解决此问题的唯一方法是追查其原因。您应该首先在第 90 行设置断点,运行代码并查看变量的大小。

或者使用dbstop if error,当您遇到错误时,它将自动调用调试器。

于 2013-10-24T19:36:32.537 回答