필터 지우기
필터 지우기

About generating the binary image from mathematical coordinates

조회 수: 1 (최근 30일)
Ki
Ki 2012년 2월 29일
Hi there,
I get a set of points in two dimensional Cartesian system, that is (x, y). My purpose is to generate a two-dimensional binary image with that coordinates. But the range for y and x are different and the step is not fixed. Actually, the pair of values are generated by random number in [0, 1] and mapping to a range with some formula
y: [-2pi, 2pi]
x: [0, 4pi]
if I plot each "point" on the figure it will show some shape actually. But my problem I don't want to plot it to a figure and then save it as image. So is that any way to convert that directly to a binary image of size N x N?
Actually, I try something like this
img = zeros(N, N);
xp = int32(x*N/(4*pi));
yp = int32((y+2*pi)*N/(4*pi));
img(xp, yp) = 1;
but it takes forever to run the program.
any better way to do that? Thanks.

답변 (1개)

Walter Roberson
Walter Roberson 2012년 2월 29일
Use vectors of xp and yp, and use subsref() to do the assignment.
fix() or round() might be more efficient than int32()
  댓글 수: 1
Ki
Ki 2012년 2월 29일
Thanks for your reply. I try round, seems a bit faster but still not good enough. But the way, I try to following the doc but still can't subsref to work. By the way, if I plot(x, p), it do show me the correct image. However, if I use above relation to write it to a matrix img (I try for small matrix size) and then plot img, it doesn't show me what I expect. Is the mapping sort of incorrect?

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by