How do you set every other row as well as every other column to zero?

21 次查看(过去 30 天)
Using a phantom...
P = phantom('Modified Shepp-Logan',256);
And plotting it with a fourier transform
n = 256;
Fp = fft2(P,n,n);
How would I remove certain rows and columns?

采纳的回答

Dave B
Dave B 2021-11-16
编辑:Dave B 2021-11-16
To remove every other column, set it to empty. You can do "every other" generally using A:2:B where A is the first value and B is the last value, and you can stick this in as an index.
a=reshape(1:25,5,5)
a = 5×5
1 6 11 16 21 2 7 12 17 22 3 8 13 18 23 4 9 14 19 24 5 10 15 20 25
a1=a;
a1(1:2:end,:)=[] % remove every other row
a1 = 2×5
2 7 12 17 22 4 9 14 19 24
a2=a;
a2(2:2:end,:)=[] % remove every other row starting at the second row
a2 = 3×5
1 6 11 16 21 3 8 13 18 23 5 10 15 20 25
a3=a;
a3(:,1:2:end)=[] % remove every other column
a3 = 5×2
6 16 7 17 8 18 9 19 10 20
a4=a;
a4(:,1:2:end)=0 % set every other row/column to 0
a4 = 5×5
0 6 0 16 0 0 7 0 17 0 0 8 0 18 0 0 9 0 19 0 0 10 0 20 0
% If you really feel like you have to do both at once, you can. But it
% would be much easier to just do rows and columns sequentially.
a5=a;
[r,c]=meshgrid(1:size(a5,1),1:size(a5,2));
ind=sub2ind(size(a5),r(mod(r,2)==0 | mod(c,2)==0),c(mod(r,2)==0 | mod(c,2)==0));
a5(ind)=0
a5 = 5×5
1 0 11 0 21 0 0 0 0 0 3 0 13 0 23 0 0 0 0 0 5 0 15 0 25
Note if your goal is to resize the image or the fft by half, imresize will give you more options

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by