convert randomly spaced data points to an image

1 Ansicht (letzte 30 Tage)
AP
AP am 13 Okt. 2012
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 Kommentare
Matt J
Matt J am 13 Okt. 2012
Bearbeitet: Matt J am 13 Okt. 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?
AP
AP am 13 Okt. 2012
You are right. The points' thickness are zero. How about saving subplot(2,1,1) as a jpg and work from there?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Matt J
Matt J am 13 Okt. 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.

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by