how to generate pixel images from scatter points
Show older comments
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
Ameer Hamza
on 4 May 2020
Do you want to show those points as dots on a blank?
Maryam Hajizadeh
on 4 May 2020
Ameer Hamza
on 4 May 2020
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?
Maryam Hajizadeh
on 4 May 2020
Answers (1)
Image Analyst
on 4 May 2020
1 vote
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
Marco A. Acevedo Z.
on 8 Apr 2021
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,
Image Analyst
on 9 Apr 2021
@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().
Marco A. Acevedo Z.
on 12 Apr 2021
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.
Image Analyst
on 12 Apr 2021
No, you'd have to use scatteredInterpolant on each channel
[r, g, b] = imsplit(rgbImage);
rInterp = scatteredInterpolant(r, .....)
gInterp = scatteredInterpolant(g, .....)
bInterp = scatteredInterpolant(b, .....)
Marco A. Acevedo Z.
on 6 Sep 2021
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.
Categories
Find more on Scatter Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!