how to generate pixel images from scatter points

Hello,
I have 55 scatter points in 2D. I have the xy coordinate of each point as well as an intensity for that point. In fact, I can assign a color to each point. I want to convert these scatter points into pixel-base images. The goal is to finally compare the data of these scatter points to the data of a previous image. Does somebody have an idea of how to generate the image with specified grid size from the scatter points?

6 Comments

Do you want to show those points as dots on a blank?
No I want to use the acquired image for statistical analysis using SPM toolbox (statistical analysis on 2D images).
darova
darova on 4 May 2020
Edited: darova on 4 May 2020
You want interpolate data or just to fill appropriate pixels?
But how do you want to create an image with 55 points? What will be the width and height of the image? How are 55 values used to calculate the colors of all pixels?
I also want to interpolate the data to make the image the same size as my other image. However, if you give me a clue of how to fill appropriate pixels, then I can find a way to intepolate them.

Sign in to comment.

Answers (1)

See my attached demo of how to use scatteredInterpolant() to make a 2-D image from a bunch of random (x,y) points.

5 Comments

Thanks for the demo. I spent half a day figuring the same code and found your example later on. For any future reader, check that you know how to interpolate unstructured points (X, Y) and generate images from them, it is very important. For example, it can be useful doing non-linear transformation (distortion correction of images). I have a small question. Do you know if there is a function in MatLab or elsewhere that allows 2D interpolation with >1 value? It would be very much efficient operating on many more channels with the same linear weights (without recalculating everything in a loop). 1Gb image takes 90 minutes correcting distortion due to this. Cheers,
@Marco Andres Acevedo Zamora scatteredInterpolant, griddedInterpolant() and interp2() can all do that on 2-D data sets. For higher dimensions than 2, you can use interpn().
Dear Image Analyst, it is true. Yet, they operate on X and Y not allowing a V with > 1 dimension. Interpn works on a grid isn't it? I have scattered data points with RGB channels. Thus, I had to calculate an interpolant for each channel with X and Y data. Sorry for the confusion.
Is there a way to do that? Ty.
No, you'd have to use scatteredInterpolant on each channel
[r, g, b] = imsplit(rgbImage);
rInterp = scatteredInterpolant(r, .....)
gInterp = scatteredInterpolant(g, .....)
bInterp = scatteredInterpolant(b, .....)
Hi Image Analyst,
As you correctly pointed out. scatteredInterpolant had to be used. I was able to improve the efficiency of the processing in RGB images using the "parallel computing toolbox" (number of workers: 4, in my i5 CPU) and reutilizing the same interpolant for the 3 channels. That is updating the F_c.Values for reinterpolating on the same coordinates each channel. These changes improved x4 and x2 the efficiency of the process respectively, as measured by the tic; t= toc; technique. With x8 improvement, the 2 hrs 20 min of my first comment were reduced to 24min 50 sec for RGB images. I hope this is useful for somebody else.
Thanks for the suggestion and good luck.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!