When I run this code an error occurs that says array indices must be positive or logical values.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
David Hill
le 22 Mar 2022
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 commentaires
David Hill
le 22 Mar 2022
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
le 23 Mar 2022
This is one of our most asked FAQ's. So see the FAQ on this error for a thorough discussion:
0 commentaires
Voir également
Catégories
En savoir plus sur Spline Postprocessing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
