what i can do to solve this problem
7 views (last 30 days)
Show older comments
Rony ali
on 23 Nov 2019
Commented: Walter Roberson
on 25 Nov 2019
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 Comments
Accepted Answer
Walter Roberson
on 24 Nov 2019
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);
0 Comments
More Answers (1)
See Also
Categories
Find more on Downloads in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!