what i can do to solve this problem

6 ビュー (過去 30 日間)
Rony ali
Rony ali 2019 年 11 月 23 日
コメント済み: Walter Roberson 2019 年 11 月 25 日
IMG = imread('X_Ray_Chest_Side.png');
origin=rgb2gray(IMG);
[M,N] = size(IMG);
figure,
imshow(origin);
title('origin image');
E=ones(5,5);
E_lpf=(1/25)*E;
f_padded=double(padarray(origin,[2 2]));
g_padded=(zeros(M+4,N+4));
for i=3:M+2
for j=3:N+2
T=f_padded(i-2:i+2,j-2:j+2);
conv_T=T.*E_lpf;
g_padded(i,j)=sum(sum(conv_T));
end
end
EEE=g_padded(2:M+1,2:N+1);
figure
imshow(uint8(EEE))
W_2=[4 8 16 32 16 8 4;8 16 32 64 32 16 8;16 32 64 128 64 32 16;32 64 128 256 128 64 32;16 32 64 128 64 32 16;8 16 32 64 32 16 8;4 8 16 32 16 8 4];
W_Gaus=(1/1936)*W_2;
g2=(zeros(m+4,n+4));
for q1=3:(m-2)
for p1=3:(n-2)
origin=add(q1-2:q1+2,p1-2:p1+2);
org=double(origin);
res=W_Gaus .*org;
g2(q1,p1)=sum(sum(res));
end
end
g2=g2(3:m+2,3:n+2);
imshow(uint8(g2));
title(' gaussian filter ');
W_composite=[0 -1 0;-1 5 -1;0 -1 0];
f2=double(add2);
g3=(zeros(m+6,n+6));
for i=1:m-3
for j=1:n-3
temp3=f2(i:i+2,j:j+2);
conv_temp3=temp3.*W_composite;
g3(i,j)=sum(sum(conv_temp3));
end
end
g3=g3(4:m+3,4:n+3);
imshow(uint8(g3));
title('Composite laplacian filter');
  3 件のコメント
Rony ali
Rony ali 2019 年 11 月 24 日
this is my homework i try to write the code correctly but i cant complete and i have a mistakes and i dont know how to solve it ....gg.pngth
Rony ali
Rony ali 2019 年 11 月 24 日
this is the error
Index in position 2 exceeds array bounds (must not exceed 1200).
Error in (line 15)
T=f_padded(i-2:i+2,j-2:j+2);

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2019 年 11 月 24 日
IMG = imread('X_Ray_Chest_Side.png');
origin=rgb2gray(IMG);
[M,N] = size(IMG);
%...
g2=(zeros(m+4,n+4));
You define variables M and N, but you do not define variables m or n, but you expect to be able to use values up to m or n as indices even though whatever values for them you happen to have in your workspace might be totally unrelated to the size of the image.
However, if you were to recode m as M and n as N then you would still have a problem. You would not be calling rgb2gray(IMG) unless IMG is rgb, but when you take
[M,N] = size(IMG);
you are asking for two output variables to store the size information about the 3 dimensional array IMG. MATLAB does define the result, but the result of
[M,N] = size(IMG);
for a 3D array is not the same as
temp = size(IMG);
M = temp(1); N = temp(2);
Instead, the result is the same as
temp = size(IMG);
M = temp(1);
N = prod(temp(2:end));
for example if IMG is 1024 x 1200 x 3 (because it is RGB) then [M,N] = size(IMG) will give M = 1024, N = (1200*3)
It is recommended that in MATLAB you get in the habit of only using size() with one output, either in the form
all_sizes = size(ARRAY)
to return all of the dimensions at once, or else in the form
specific_size = size(ARRAY, dimension_number)
In this particular case, the problem would also have been avoided if you had used
[M,N] = size(origin);

その他の回答 (1 件)

Rony ali
Rony ali 2019 年 11 月 25 日
[M,N] = size(origin);
i use it function but now what i can do about undefined values m,n
  2 件のコメント
Rony ali
Rony ali 2019 年 11 月 25 日
THIS IS THE NEW ERROR
Undefined function 'add' for input arguments of type 'double'.
Error in rawand (line 32)
origin=add(q1-2:q1+2,p1-2:p1+2);
>>
Walter Roberson
Walter Roberson 2019 年 11 月 25 日
Perhaps add should be g_padded?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDownloads についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by