Create image from pixels using two vectors and their grayscale value
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a very basic understanding of matlab. What I am trying to do is use X,Y,Z datapoints and their grayscale value (how dark or how light the pixel is) to reconstruct an image of a chest X-Ray pixel-by-pixel. I have over 5 million data points and all of the Y data points are zero. I am having a hard time accomplishing it. Do you have any tips? Thank you!
2 comentarios
DGM
el 26 de Oct. de 2021
Editada: DGM
el 26 de Oct. de 2021
How exactly is the data arranged? What are the vector/array sizes? If x and y are vectors and z is a 2D array representing intensity, then you should simply be able to use z without regard for x or y. If x,y,z are positional information and you have a fourth array for intensity information, then you should be able to do the same, as the positional information is constant-valued along one axis (y), implying that all the points are coplanar.
It would help if you could provide an example of the data.
Respuesta aceptada
DGM
el 26 de Oct. de 2021
Editada: DGM
el 28 de Oct. de 2021
I'm pretty sure there are other ways to do this, but here's one way.
% build example image and position data
A = imread('coins.png').';
[z x] = meshgrid(1:size(A,2),1:size(A,1));
x = 0.1*x(:)+1; % just to show that this works for non-integers
z = 0.1*z(:)+1;
y = zeros(size(x));
A = A(:);
% at this point, you have four vectors
% one way to rectify the image
imheight = numel(unique(z));
imwidth = numel(unique(x));
B = reshape(A,imwidth,imheight).';
imshow(B)
Depending on the class and range of the intensity data, you might need to scale/cast the image in order for it to display or save correctly. I imagine the intensity data was originally int16 or uint16. If it has been cast as double, make sure to either normalize it or cast it back to the original integer class.
EDIT:
If this is the same as this:
the file needs to be read into the workspace so that the vectors are available. This may be one way:
a = dlmread('testfile.txt');
x = a(:,1);
z = a(:,3);
A = mat2gray(a(:,4)); % normalize
In this example, I'm ignoring the format and scaling of the intensity data and just normalizing it. That should result in a properly-scaled image regardless of the original class.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!