convert randomly spaced data points to an image
1 view (last 30 days)
Show older comments
Dear All,
I have a set of randomly spaced 2D data and would like to convert it into an image. I want to create an image whose intensity is 255 on the random points and zero elsewhere. I interpolate the data into a fine and evenly spaced grid (meshgrid format) using the following code but I failed. After I interpolate, the image is not an exact match or even close to the representation of random points. If you compare subplot(2,1,1) and subplot(2,1,2) in the following code, it can be seen that all the space between the random points gets 255. Is there a better way to convert the data to an image?
I would be grateful for any help.
Ahmad
% Range of random number for x and y.
L = 8;
H = 6;
% The number of random numbers.
n = 100;
% Randomly spaced data.
x = rand( n, 1 )*L;
y = rand( n, 1 )*H;
% Intensity of the data points are 'White'.
intensity = ones(size(x))*255;
subplot( 2,1,1 )
plot( x, y, '.' )
% Interpolate the data into a rectangular evenly spaced grid.
[ X, Y ] = meshgrid( 0:0.01:L, 0:0.01:H );
F = TriScatteredInterp( x, y, intensity );
intensityInterp = F( X, Y );
subplot(2,1,2)
imshow( intensityInterp )
2 Comments
Matt J
on 13 Oct 2012
Edited: Matt J
on 13 Oct 2012
Since points are points, and therefore occupy no area, wouldn't you expect the image to be completely zero unless one of your X,Y meshgrid sample locations happened to exactly coinicide with one of the randomly scattered points?
If so, why not just do intensityInterp=zeros(...) and be done with it?
Answers (1)
Matt J
on 13 Oct 2012
You might also try adding lots of additional scattered points with intensity zero. That will give the interpolation code information about what intensity lies in between the high intensity points.
In any case, whatever interpolator you choose, you will be accepting the interpolator's idea of how the intensity transitions from high to zero. So, to inform that choice, you have to have some idea of what you want that transition to be.
0 Comments
See Also
Categories
Find more on Interpolation 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!