Info

This question is locked. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Not getting a full image from raw data

조회 수: 5 (최근 30일)
Hayley Devine
Hayley Devine 2024년 6월 25일
Locked: Rena Berman 2024년 7월 10일
I am trying to make an Xray image using x, y, and z coordinates of raw data. Here is what I have:
data = readmatrix('Chest_XRay_Raw_Data.txt');
% Extract x, y, z coordinates and grayscale values
x = data(:,1);
y = data(:,2);
z = data(:,3); % If needed, otherwise ignore
grayscale = data(:,4);
%Find bounds
x_range = min(x):max(x);
y_range = min(y):max(y);
% Initialize the image matrix
image = zeros(length(y_range), length(x_range));
% Populate the image matrix with grayscale values
for i = 1:length(x)
x_idx = find(x_range == x(i));
y_idx = find(y_range == y(i));
image(y_idx, x_idx) = grayscale(i);
end
%normalize image
image = mat2gray(image);
% Display the image
imshow(image);
title('Reconstructed Image from Raw Data');
Raw data example:
+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
+4.23109600E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.22939700E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.22769700E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.22599800E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.22429900E+002, +0.00000000E+000, +0.00000000E+000, +420
An image window pops up with only one solid line with a little blank space in the middle. Any suggestions to fix this?
  댓글 수: 3
Voss
Voss 2024년 6월 25일
편집: Voss 2024년 6월 25일
How about if you compress it to a zip archive, or copy and paste the first ten thousand or so lines of text into a new text file and upload that?
Rena Berman
Rena Berman 2024년 7월 10일

(Answers Dev) Restored edit

답변 (1개)

Walter Roberson
Walter Roberson 2024년 6월 25일
x_range = min(x):max(x);
y_range = min(y):max(y);
That code assumes that most of the x and y are integers (or at least integers plus a constant offset).
+4.23789300E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.23619400E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.23789300E+002 is not an integer. +4.23619400E+002 is not an integer either -- and it is not the same constant offset relative to the other non-integer.
  댓글 수: 1
Walter Roberson
Walter Roberson 2024년 6월 26일
is there a command o fix this?
Not without a lot of assumptions.
You would need to find the common divisor between the differences in values, and scale everything by that common divisor.
format long g
A = [+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
+4.23109600E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.22939700E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.22769700E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.22599800E+002, +0.00000000E+000, +0.00000000E+000, +420
+4.22429900E+002, +0.00000000E+000, +0.00000000E+000, +420];
udA = unique(diff(sort(A(:,1))))
udA = 4x1
0.169899999999984 0.169900000000041 0.169999999999959 0.170000000000016
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
you would have to scale by something that divides each of those.
Unless you are willing to round to the nearest 0.17...
RA = round(A(:,1)/0.17)
RA = 9x1
2493 2492 2491 2490 2489 2488 2487 2486 2485
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
take the max() and min() of urA as the range of values,
[minRA, maxRA] = bounds(RA);
sRA = RA - minRA + 1
sRA = 9x1
9 8 7 6 5 4 3 2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

This question is locked.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by