Create an image from x and y locations with greyscale value
Show older comments
I am asking essentially this same question, but I do not understand how to go from the vectors to the image without starting with an image (which I do not have). I would prefer a pixelated image I can export e.g. with imwrite, rather than plotting points on a graph and colouring by the z value (which is my backup plan).
I want to create an image when the only information I have is pixel locations (which I can round to a grid) and the greyscale at those points. The pixel locations will not be integers. Here is a small example with 9 data points.
X Y Greyscale
0 0 255
0 0.5 70
0 1 111
0.5 0 26
0.5 0.5 26
0.5 1 255
1 0 108
1 0.5 26
1 1 70
Accepted Answer
More Answers (1)
KSSV
on 16 Aug 2022
data = [0 0 255
0 0.5 70
0 1 111
0.5 0 26
0.5 0.5 26
0.5 1 255
1 0 108
1 0.5 26
1 1 70] ;
x = data(:,1) ;
y = data(:,2) ;
z = data(:,3) ;
nx = length(unique(x)) ;
ny = length(unique(y)) ;
X = reshape(x,ny,nx) ;
Y = reshape(y,ny,nx) ;
Z = reshape(z,ny,nx) ;
Categories
Find more on Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!