# convert randomly spaced data points to an image

3 ビュー (過去 30 日間)
AP 2012 年 10 月 13 日
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.
% 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 件のコメント表示非表示 1 件の古いコメント
AP 2012 年 10 月 13 日
You are right. The points' thickness are zero. How about saving subplot(2,1,1) as a jpg and work from there?

サインインしてコメントする。

### 回答 (1 件)

Matt J 2012 年 10 月 13 日
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.

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!