what i can do to solve this problem

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 个评论

What problem?
You have presented a bunch of undocumented code (and no copy of the input image). We must assume that the purpose of the code is to do exactly whatever it is that the code does, and that therefore the code is perfect.
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
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);

请先登录,再进行评论。

 采纳的回答

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 个评论

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);
>>
Perhaps add should be g_padded?

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Downloads 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by