Making an Xray image out of x, y, z coordinates ERROR
I am trying to make an xray image out of given x, y, z coordinates. Here is my code below:
fileID = fopen(‘Chest_Xray_Raw_Data.txt’, ‘r’);
data = textscan(fileID, ‘%f,%f,%f,%f’, ‘Delimiter’, ‘,’);
fclose(fileID);
% Extract x, y, z coordinates and grayscale values
x = data{1};
y = data{2};
z = data{3}; % If needed, otherwise ignore
grayscale = data{4};
% Determine the size of the image
maxX = int64(max(x));
maxY = int64(max(y));
% Normalize coordinates to fit into the pixel grid
x = round(x – min(x) + 1);
y = round(y – min(y) + 1);
% Initialize the image matrix
imageMatrix = zeros(maxY, maxX);
% Populate the image matrix with grayscale values
for i = 1:length(x)
imageMatrix(y(i), x(i)) = grayscale(i);
end
% Display the image
figure;
imshow(imageMatrix, []);
title(‘Reconstructed Image from Raw Data’);
colormap(gray); % Use grayscale colormap
colorbar;
An example of the data I am given is this, but obviously larger:
+4.23789300E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.23619400E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.23449400E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.23279500E+002, +0.00000000E+000, +0.00000000E+000, +420
When I run it, I get this message
"Index exceeds the number of array elements. Index must not exceed 0.
Error in untitled (line 24)
imageMatrix(y(i), x(i)) = grayscale(i);"
How can I get rid of this error message? Thanks!I am trying to make an xray image out of given x, y, z coordinates. Here is my code below:
fileID = fopen(‘Chest_Xray_Raw_Data.txt’, ‘r’);
data = textscan(fileID, ‘%f,%f,%f,%f’, ‘Delimiter’, ‘,’);
fclose(fileID);
% Extract x, y, z coordinates and grayscale values
x = data{1};
y = data{2};
z = data{3}; % If needed, otherwise ignore
grayscale = data{4};
% Determine the size of the image
maxX = int64(max(x));
maxY = int64(max(y));
% Normalize coordinates to fit into the pixel grid
x = round(x – min(x) + 1);
y = round(y – min(y) + 1);
% Initialize the image matrix
imageMatrix = zeros(maxY, maxX);
% Populate the image matrix with grayscale values
for i = 1:length(x)
imageMatrix(y(i), x(i)) = grayscale(i);
end
% Display the image
figure;
imshow(imageMatrix, []);
title(‘Reconstructed Image from Raw Data’);
colormap(gray); % Use grayscale colormap
colorbar;
An example of the data I am given is this, but obviously larger:
+4.23789300E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.23619400E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.23449400E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.23279500E+002, +0.00000000E+000, +0.00000000E+000, +420
When I run it, I get this message
"Index exceeds the number of array elements. Index must not exceed 0.
Error in untitled (line 24)
imageMatrix(y(i), x(i)) = grayscale(i);"
How can I get rid of this error message? Thanks! I am trying to make an xray image out of given x, y, z coordinates. Here is my code below:
fileID = fopen(‘Chest_Xray_Raw_Data.txt’, ‘r’);
data = textscan(fileID, ‘%f,%f,%f,%f’, ‘Delimiter’, ‘,’);
fclose(fileID);
% Extract x, y, z coordinates and grayscale values
x = data{1};
y = data{2};
z = data{3}; % If needed, otherwise ignore
grayscale = data{4};
% Determine the size of the image
maxX = int64(max(x));
maxY = int64(max(y));
% Normalize coordinates to fit into the pixel grid
x = round(x – min(x) + 1);
y = round(y – min(y) + 1);
% Initialize the image matrix
imageMatrix = zeros(maxY, maxX);
% Populate the image matrix with grayscale values
for i = 1:length(x)
imageMatrix(y(i), x(i)) = grayscale(i);
end
% Display the image
figure;
imshow(imageMatrix, []);
title(‘Reconstructed Image from Raw Data’);
colormap(gray); % Use grayscale colormap
colorbar;
An example of the data I am given is this, but obviously larger:
+4.23789300E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.23619400E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.23449400E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.23279500E+002, +0.00000000E+000, +0.00000000E+000, +420
When I run it, I get this message
"Index exceeds the number of array elements. Index must not exceed 0.
Error in untitled (line 24)
imageMatrix(y(i), x(i)) = grayscale(i);"
How can I get rid of this error message? Thanks! error, grayscale MATLAB Answers — New Questions