0

実際には、次の Web サイトhttp://www.mathworks.com/matlabcentral/fileexchange/28300にコードを実装しようとしていますが、これは指定された 2 つの画像の寸法が同じ場合にのみ機能します。現在のコードでこれを行うと、エラーが発生します

??? Sub scripted assignment dimension mismatch. Error in ==> example2 at 27

27 行目:

I(:,1:size(I1,2),:)=I1; I(:,size(I1,2)+1:size(I1,2)+size(I2,2),:)=I2; 

私のためにこれを解決できますか?

4

1 に答える 1

1

小さい画像をゼロでパディングして、大きい画像と同じサイズにすることができます。例えば

%Start with rows:    
if size(I1,1) > size(I2,1) %I1 has more rows so pad I2
        pad = zeros (size(I1,1) - size(I2,1), size(I2,2));
        I2 = [I2 ; pad]; %Append the rows of zeros to the bottom of I2
else %I2 has more rows so pad I1
        pad = zeros (size(I2,1) - size(I1,1), size(I1,2));
        I1 = [I1 ; pad]; %Append the rows of zeros to the bottom of I1

%Pad the columns    
if size(I1,2) > size(I2,2) %I1 has more rows so pad I2
        pad = zeros (size(I2,1), size(I1,2) - size(I2,2));
        I2 = [I2 , pad]; %Append the columns of zeros to the left of I2
else %I2 has more rows so pad I1
        pad = zeros (size(I1,1), size(I2,2) - size(I1,2));
        I1 = [I1 , pad]; %Append the columns of zeros to the left of I1

私はそれをテストしていないので、おそらく size(I2,2) - size(I1,2) + 1 の代わりに size(I2,2) - size(I1 のように、寸法を完璧にするために少しいじる必要があるかもしれません、2)、そのようなこと。

ただし、最初に、何をしようとしているかのロジックを理解する必要があります。ゼロでパディングすることは、アプリケーションでは意味がない場合があります。また、私のコードは下と左にパッドを入れていますが、画像が新しい画像の中央にくるように、ずっとパディングしたいかもしれません。

于 2012-04-17T07:11:25.620 に答える