Attempt to grow array along ambiguous dimension
5 views (last 30 days)
Show older comments
i have an error in me code in the last part
Attempt to grow array along ambiguous dimension.
the code:
%A Read and resize the image to 500*500
I=imread('letters.jpg');
Ir=imresize(I,[500,500]);
%B FFT on the image
F=fftshift(fft2(Ir));
%C gaussian low pass filter withe r=15
r=15;
[rows,cols]=size(Ir);
[x,y]=meshgrid(1:cols, 1:cols);
centerx=round(cols/2);
centery=round(rows/2);
distance=sqrt((x-centerx).^2+(y-centery).^2);
gaussian=exp(-(distance.^2)/(2*r^2));
gaussian=imresize(gaussian,[500,500]);
filteredimage=F.*gaussian;
%D inverse fourier transform and display in real space
filteredimage=ifft2(ifftshift(filteredimage));
filteredimage=real(filteredimage);
subplot(421),imshow(filteredimage),title('Filtered Image r=15');
%E Repeat c and d on b using a radius of 50 and 150 pixels
r2=50;
r3=150;
distance2=sqrt((x-centerx).^2+(y-centery).^2);
gaussian2=exp(-(distance2.^2)/(2*r2^2));
gaussian2=imresize(gaussian2,[500,500]);
filteredimage2=F.*gaussian2;
filteredimage2=ifft2(ifftshift(filteredimage2));
filteredimage2=real(filteredimage2);
subplot(422),imshow(filteredimage2),title('Filterd Image r=50');
distance3=sqrt((x-centerx).^2+(y-centery).^2);
gaussian3=exp(-(distance3.^2)/(2*r3^2));
gaussian3=imresize(gaussian3,[500,500]);
filteredimage3=F.*gaussian3;
filteredimage3=ifft2(ifftshift(filteredimage3));
filteredimage3=real(filteredimage3);
subplot(423),imshow(filteredimage3),title('Filterd Image r=150');
%F Butterworth high pass filter on the image of b with D0=15 and D0=50
D01=15;
D02=50;
n=2; %Order of Butterworth filter
distance4= sqrt((x-centerx).^2+(y-centery).^2);
butterworthF1=1-1./(1+(distance4./D01).^(2*n));
butterworthF1=imresize(butterworthF1,[500,500]);
filteredimage4= F .* butterworthF1;
filteredimage4=ifft2(ifftshift(filteredimage4));
filteredimage4=real(filteredimage4);
subplot(424),imshow(filteredimage4),title('Butterworth high pass filter D0=15');
butterworthF2=1-1./(1+(distance4./D02).^(2*n));
butterworthF2=imresize(butterworthF2,[500,500]);
filteredimage5= F .* butterworthF2;
filteredimage5=ifft2(ifftshift(filteredimage5));
filteredimage5=real(filteredimage5);
subplot(425),imshow(filteredimage5),title('Butterworth high pass filter D0=50');
%D Ideal High pass filter with D0=15 and 50
idealF1=ones(size(Ir));
idealF1(distance4 <= D01)=0;
filteredimage6= F.* idealF1;
filteredimage6=ifft2(ifftshift(filteredimage6));
filteredimage6=real(filteredimage6);
subplot(426),imshow(filteredimage6),title('Ideal High pass filter D0=15');
idealF2=ones(size(Ir));
idealF2(distance4 <= D02)=0;
filteredimage7= F.* idealF2;
filteredimage7=ifft2(ifftshift(filteredimage7));
filteredimage7=real(filteredimage7);
subplot(427),imshow(filteredimage7),title('Ideal High pass filter D0=50');
0 Comments
Answers (2)
Walter Roberson
on 25 May 2023
Suppose you have
A = [1 2 3; 4 5 6]
which is a 2 x 3 array.
Now suppose you assign to A(7) using linear indexing. Should MATLAB expand the array to 2 x 4, or should it expand the array to 3 x 3 ?
A(7) = 50
When you have a vector (N x 1 or 1 x N or even 1 x 1 x 1 x 1 x N) then when you use linear or logical indexing to extend the vector then it is pretty clear which dimension should be extended -- the one where all of the information is currently. And when you have a scalar, then there is a special case that assigning outside of the 1 x 1 scalar bounds results in a row vector. But when you have an array with two or more non-singular dimensions and ask to use linear or logical indexing to extend the array, then it is not clear what is being asked.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!