When I run this code an error occurs that says array indices must be positive or logical values.
3 次查看(过去 30 天)
显示 更早的评论
clc;
close all;
clear;
PD=phantom('Modified Shepp-Logan');
padimage = [2,2];
PD= padarray(PD,padimage);
subplot(2,3,1)
imagesc(PD);
colormap('gray');
title('Modified Shepp-Logan')
freq = 2;
thetas = 0:freq:180;
gtheta = length(thetas);
gl = size(PD,1);
sinogram = zeros(gl,gtheta);
for i = 1:length(thetas)
tmpImage = imrotate(PD,-thetas(i),'bilinear','crop');
sinogram(:,i) = sum(tmpImage);
end
subplot(2,3,2)
imagesc(sinogram);
title('Circle Sinogram');
thetas=0;
Fl = size(sinogram,1);
Ftheta = length(thetas);
thetas = (pi/180)*thetas;
g0 = zeros(Fl,Fl);
Fmid = ceil(Fl/2);
[x,y] = meshgrid(ceil((-Fl)/2):ceil(Fl/2-1));
for i = 1:Ftheta
rotCoords = Fmid+round(x*sin(thetas(i)) + y*cos(thetas(i)));
rotCoords=floor(abs(rotCoords));
g0 = g0 + sinogram(rotCoords,i)./Ftheta;
end
subplot(2,3,3);
imagesc(g0);
title('Simple backprojection')
% Here is the error
Index in position 1 is invalid. Array indices must be positive integers or logical
values.
Error in P4P2 (line 41)
g0 = g0 + sinogram(rotCoords,i)./Ftheta;
0 个评论
回答(2 个)
David Hill
2022-3-22
Not sure what you are trying to do, but rotCoords is 260x260 and sinogram is a 260x91. You cannot index inside sinogram with rotCoords, you will get that error message.
3 个评论
David Hill
2022-3-22
g0 = g0 + sinogram(rotCoords+1)./Ftheta;%rotCoords has values of 0 to 259. You cannot linear index with zero. Adding 1 will allow linear indexing into sinogram.
Image Analyst
2022-3-23
This is one of our most asked FAQ's. So see the FAQ on this error for a thorough discussion:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!