【问题标题】:Concatenation error when trying to set 'xlabel'尝试设置“xlabel”时出现连接错误
【发布时间】:2017-03-19 15:41:55
【问题描述】:

该程序旨在对 lena 图像执行 DWT/IDWT 和 EZW 编码/解码。当我打算用压缩比和均方误差信息指定重建图像时,问题出现在最后。

clc
clear all;
close all;
T_min=32;

I=imread('lena.jpg');
infilename = 'lena.jpg'
figure(1)
subplot(2,1,1)
imshow(I);
title('original Image');
img_orig = double(imread(infilename));
dim=size(I,1);
[LL1,LH1,HL1,HH1] = dwt2(I,'haar');
[LL2,LH2,HL2,HH2] = dwt2(LL1,'haar');
[LL3,LH3,HL3,HH3] = dwt2(LL2,'haar');

I5=[LL3,LH3;HL3,HH3];
I6=[I5,LH2;HL2,HH2];
I7=[I6,LH1;HL1,HH1];


max_coef = max(max(abs(I7)))
T0 = 2^floor(log2(max_coef))
d=1;
s1=1;
sym_count=0
snb=0
ref=1;
dim=size(I,1);
count=1
symbol(1:dim,1:dim)='S';

while T0>=T_min
for  i= 1:size(I,1)
    for j=1:size(I,2)

    if(abs(I(i,j))<T0)
        dom(d,:)=[i,j];
        d=d+1;
        mask =  masking(i,j,dim);
        I1=double(I).*mask;
        p1=0;
         for i1=i:dim
             for j1=j:dim
                 if (I1(i1,j1)>=T0)
                     p1=1;
                 end
             end
         end
         if (p1==1)
             symbol(i,j)='I';        %% I is isolated zero
             sym_count=sym_count+1;
         else
             symbol(i,j)='Z';        %% Z is zerotree root
             sym_count=sym_count+1;
         end

    else
         if(I(i,j)<0)
            symbol(i,j)='N';         %% N is negative
            sym_count=sym_count+1;
            snb=snb+1;
            if (I(i,j)<=(-T0-T0/2))
                refine(ref)= 1;
                ref=ref+1;
            else
                refine(ref)= 0;
                ref=ref+1;
            end
         else
            symbol(i,j)='P';         %% P is positive
            sym_count=sym_count+1;
            snb=snb+1;
            if (I(i,j)>=(T0+T0/2))
                refine(ref)= 1;
                ref=ref+1;
            else
                refine(ref)= 0;
                ref=ref+1;
            end
         end
        sub(s1)=I(i,j);
        s1=s1+1;
    end
    end
end


for i=1:dim
    for j=1:dim
        if symbol(i,j)=='Z'
            mask1=masking(i,j,dim);
            for i1=i:dim
                for j1=j:dim
                    if(mask1(i1,j1)==1)
                        symbol(i1,j1)='D';
                    end
                end
            end
            symbol(i,j)='Z';
        end
    end
end

%decoding the from the significant bits (P and N)

rec=zeros(dim);
ref1=1;
for i=1:dim
    for j=1:dim
        if symbol(i,j)=='P'
            if (refine(ref1)==1)
%               rec(i,j)=T0+T0/2+T0/4;
                rec(i,j)=I7(i,j);
                ref1=ref1+1;
            else
%               rec(i,j)=T0+T0/2-T0/4;
                rec(i,j)=I7(i,j);
                ref1=ref1+1;
            end
        elseif (symbol(i,j)=='N')
            if (refine(ref1)==1)
%               rec(i,j)=-T0-T0/2-T0/4;
                rec(i,j)=I7(i,j);
                ref1=ref1+1;
            else
%               rec(i,j)=-T0-T0/2+T0/4;
                rec(i,j)=I7(i,j);
                ref1=ref1+1;
            end
        end
    end
end

I8=rec;

% reassignment for inverse DWT.
r_LL3=I8(1:dim/8,1:dim/8);
r_LH3=I8(1:dim/8,dim/8+1:2*dim/8);
r_HL3=I8(dim/8+1:2*dim/8,1:dim/8);
r_HH3=I8(dim/8+1:2*dim/8,dim/8+1:2*dim/8);
r_LL2=[r_LL3,r_LH3;r_HL3,r_HH3];
r_LH2=I8(1:dim/4,dim/4+1:2*dim/4);
r_HL2=I8(dim/4+1:2*dim/4,1:dim/4);
r_HH2=I8(dim/4+1:2*dim/4,dim/4+1:2*dim/4);
r_LL1=[r_LL2,r_LH2;r_HL2,r_HH2];
r_LH1=I8(1:dim/2,dim/2+1:2*dim/2);
r_HL1=I8(dim/2+1:2*dim/2,1:dim/2);
r_HH1=I8(dim/2+1:2*dim/2,dim/2+1:2*dim/2);
I9=[r_LL1,r_LH1;r_HL1,r_HH1];

% inverse discrete wavelet transform
r_LL2=idwt2(r_LL3,r_LH3,r_HL3,r_HH3,'haar');
r_LL1=idwt2(r_LL2,r_LH2,r_HL2,r_HH2,'haar');
img_reconstruct=idwt2(r_LL1,r_LH1,r_HL1,r_HH1,'haar');

T0=T0/2
count=count+1
image_capacity=img_orig*8
MSE = sum(sum((img_reconstruct-img_orig).^2))/size(img_orig,1)/size(img_orig,2)
CR=(image_capacity/(2*sym_count+snb))

figure(2)
subplot(3,3,count)
imshow(uint8(img_reconstruct))
title(['reconstructed Image', num2str(count)]);
% xlabel(['MSE = ',num2str(MSE,'%3.2f'),'CR', num2str(CR,'%1.2f %%')])
xlabel({['Compression Ratio: ' num2str(CR,'%1.2f %%')],['MSE: ' num2str(MSE,'%3.2f')]})

end

代码中比较麻烦的部分如下图

xlabel({['Compression Ratio: ' num2str(CR,'%1.2f %%')],['MSE: ' num2str(MSE,'%3.2f')]})

我得到的错误是

Error using horzcat
Dimensions of matrices being concatenated are not consistent.

我打算有一个几乎与此类似的情节:

我在这里做错了什么?

【问题讨论】:

  • 请向我们展示您正在使用的 CRMSE 数组...
  • Sardar,抱歉,这没用。错误仍然存​​在。
  • 您发布了一些代码这一事实很好,但它不是很有帮助,因为我们无法运行它(例如,masking 是什么?)...确实,重现问题所需的一切是CRMSE 的一些示例(完整的,或者至少是您所获得的一部分)...请参阅minimal reproducible example
  • 感谢魔鬼,我已经能够通过将 CR 从矩阵更改为单个数字来解决问题。在这段代码中,CR 和 MSE 不应该是数组。
  • 是这样想的。不客气!

标签: matlab plot concatenation matlab-figure axis-labels


【解决方案1】:

我想我已经发现这里出了什么问题。我使用 CR 作为矩阵,但它应该是一个数字。我只需要引入以下更改。

T0=T0/2
count=count+1
image_capacity=dim*dim*8
MSE = sum(sum((img_reconstruct-img_orig).^2))/size(img_orig,1)/size(img_orig,2)
CR=(image_capacity/(2*sym_count+snb))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-01
    • 2020-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-05
    相关资源
    最近更新 更多