Index in position 1 exceeds array bounds.

I'm having an error on line 25.Error about “Index in position 1 exceeds array bounds. ”
the following is the code from the first to the last line
clc;clear;close all;
I = dicomread('IM-0001-0008.dcm');
figure(1), imshow(I,[]);
BW = I>3000;
figure(2), imshow(BW,[]);
s = regionprops(BW, 'centroid');
centroids = cat(1,s.Centroid);
% labelling
[B,L] = bwboundaries(BW,'noholes');
[~,num] = bwlabel(BW,8);
figure(3), imshow(I,[])
hold on
for k = 1:num
boundary = B{k};
text(boundary(1,2)+20,boundary(1,1),strcat(['Object ',num2str(k)]),'Color','y',...
'FontSize',14,'FontWeight','bold');
plot(centroids(:,1), centroids(:,2), 'b*')
end
hold off
% object 1 & 2
x1 = centroids(1,1);
y1 = centroids(1,2);
x2 = centroids(2,1);
y2 = centroids(2,2);
figure(4), imshow(I,[])
hold on
plot([x1;x2], [y1;y2], 'r','LineWidth',3)
d_px = sum(([x1;y1]-[x2;y2]).^2).^0.5;
res = 1.4798;
d_mm = d_px/res;
text((x1+x2+20)/2,(y1+y2)/2,strcat(['d = ',num2str(d_px),' px']),'Color','y',...
'FontSize',14,'FontWeight','bold');
text((x1+x2+20)/2,(y1+y2+40)/2,strcat(['d = ',num2str(d_mm),' mm']),'Color','y',...
'FontSize',14,'FontWeight','bold');
hold off
% object 1 & 3
x1 = centroids(1,1);
y1 = centroids(1,2);
x3 = centroids(3,1);
y3 = centroids(3,2);
figure(5), imshow(I,[])
hold on
plot([x1;x3], [y1;y3], 'g','LineWidth',3)
d_px = sum(([x1;y1]-[x3;y3]).^2).^0.5;
res = 1.4798;
d_mm = d_px/res;
text((x1+x3+20)/2,(y1+y3)/2,strcat(['d = ',num2str(d_px),' px']),'Color','y',...
'FontSize',14,'FontWeight','bold');
text((x1+x3+20)/2,(y1+y3+40)/2,strcat(['d = ',num2str(d_mm),' mm']),'Color','y',...
'FontSize',14,'FontWeight','bold');
hold off
% object 1 & 4
x1 = centroids(1,1);
y1 = centroids(1,2);
x4 = centroids(4,1);
y4 = centroids(4,2);
figure(6), imshow(I,[])
hold on
plot([x1;x4], [y1;y4], 'b','LineWidth',3)
d_px = sum(([x1;y1]-[x4;y4]).^2).^0.5;
res = 1.4798;
d_mm = d_px/res;
text((x1+x4+20)/2,(y1+y4)/2,strcat('d = ',[num2str(d_px),' px']),'Color','y',...
'FontSize',14,'FontWeight','bold');
text((x1+x4+20)/2,(y1+y4+40)/2,strcat(['d = ',num2str(d_mm),' mm']),'Color','y',...
'FontSize',14,'FontWeight','bold');
hold off
% object 2 & 3
x2 = centroids(2,1);
y2 = centroids(2,2);
x3 = centroids(3,1);
y3 = centroids(3,2);
figure(7), imshow(I,[])
hold on
plot([x2;x3], [y2;y3], 'c','LineWidth',3)
d_px = sum(([x2;y2]-[x3;y3]).^2).^0.5;
res = 1.4798;
d_mm = d_px/res;
text((x2+x3)/2,(y2+y3-60)/2,strcat(['d = ',num2str(d_px),' px']),'Color','y',...
'FontSize',14,'FontWeight','bold');
text((x2+x3)/2,(y2+y3-20)/2,strcat(['d = ',num2str(d_mm),' mm']),'Color','y',...
'FontSize',14,'FontWeight','bold');
hold off
% object 2 & 4
x2 = centroids(2,1);
y2 = centroids(2,2);
x4 = centroids(4,1);
y4 = centroids(4,2);
figure(8), imshow(I,[])
hold on
plot([x2;x4], [y2;y4], 'm','LineWidth',3)
d_px = sum(([x2;y2]-[x4;y4]).^2).^0.5;
res = 1.4798;
d_mm = d_px/res;
text((x2+x4+20)/2,(y2+y4)/2,strcat(['d = ',num2str(d_px),' px']),'Color','y',...
'FontSize',14,'FontWeight','bold');
text((x2+x4+20)/2,(y2+y4+40)/2,strcat(['d = ',num2str(d_mm),' mm']),'Color','y',...
'FontSize',14,'FontWeight','bold');
hold off
% object 3 & 4
x3 = centroids(3,1);
y3 = centroids(3,2);
x4 = centroids(4,1);
y4 = centroids(4,2);
figure(9), imshow(I,[])
hold on
plot([x3;x4], [y3;y4], 'y','LineWidth',3)
d_px = sum(([x3;y3]-[x4;y4]).^2).^0.5;
res = 1.4798;
d_mm = d_px/res;
text((x3+x4+20)/2,(y3+y4)/2,strcat(['d = ',num2str(d_px),' px']),'Color','y',...
'FontSize',14,'FontWeight','bold');
text((x3+x4+20)/2,(y3+y4+40)/2,strcat(['d = ',num2str(d_mm),' mm']),'Color','y',...
'FontSize',14,'FontWeight','bold');
hold off

回答(1 个)

Your dicom image has no data that is greater than 3000.
There are a couple of different conventions for CT images. In one of the conventions the range starts from 0 and anything less than about 3000 is considered to be water to be ignored. In the other convention, the range starts negative and anything less than 0 is considered water to be ignored. You might have encountered one of those files (but it would be uncommon for there to be no data above 3000 for those)
It is also possible that the image is not CT at all. MRI is sometimes just 8 bits.

5 个评论

Do you have a dicom image that fits the criteria?
I don't have a dicom image that fits the criteria, because this is a daily assignment from campus
-Thank you
You have not defined any criteria.
I suggest that you use imhist() to see the distribution of values in your image.
can you help me solve my mistake,
I still do not understand
We are unable to assist you because you have not stated what your goals are.
You have an DICOM image that you have not posted. We, as volunteers, do not know what the range of values of the image is. From the behaviour of your program, we can deduce that it has no data values greater than 3000. You can examine the distribution of values in the image by using
imhist(I)
You could use the information you gain from that histogram in order to experiment with using different thresholds instead of the hard-coded 3000 in
BW = I>3000;
You asked for a dicom image that "fits the criteria". But you did not say what the criteria is. Are you looking for a brain aneurysm CT scan? Are you looking for a lung XRAY which shows evidence of tuberculosis ? Are you looking for a knee image that shows bone degeneration ?
And why would you go looking for a different image instead of just adjusting the 3000 in your existing program? Is the assignment to research to find some image that the program works with? Or is the assignment to adjust the program to work with the image(s) that you already have?
My goal is only to complete the assignments given by the lecturer.
the following dicom image that I have.
I think the dicom image I have doesn't match.
please help me to solve this problem.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Medical Physics 的更多信息

产品

版本

R2020a

提问:

2021-7-21

评论:

2021-7-23

Community Treasure Hunt

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

Start Hunting!

Translated by