32 views (last 30 days)

Hello

I have two vectors of X and Y cartesian values in +/-, how to convert them to a binary image of 0's and 1's

Thank you.

I attached my plot.

Ameer Hamza
on 14 Jun 2020

Something like this

x = randn(1, 5000); % generate random points

y = randn(1, 5000);

img_dimension = [500 500]; % [width height]

img = zeros(img_dimension);

xt = floor(rescale(x, 1, img_dimension(2))); % convert x-y in range of image coordinates

yt = floor(rescale(y, 1, img_dimension(1)));

idx = sub2ind(img_dimension, yt, xt);

img(idx) = 1;

imshow(img)

Ameer Hamza
on 21 Jun 2020

Ameer Hamza
on 21 Jun 2020

You can make the circle small and large by specifying the range of rescale() function

xt = floor(rescale(x, 100, img_dimension(2)-100)); % convert x-y in range of image coordinates

yt = floor(rescale(y, 100, img_dimension(1)-100));

create a circle between 100 to 400 pixels, i.e., leave 100 pixels on all sides unoccupied.

Thiago Henrique Gomes Lobato
on 14 Jun 2020

This is an general example you could use:

Cartesian = [ 10,1;

15,10];

imSize=20;

binaryImage= false(imSize);

Cartesian(:,2) = imSize-(Cartesian(:,2)-1); % Comment if you want zero at the top-left corner

for idx=1:size(Cartesian,1)

binaryImage(Cartesian(idx,2),Cartesian(idx,1)) = true; % Note that X-Y index are inverted in indexing

end

figure,imshow(binaryImage)

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/547905-converting-cartesian-coordinates-to-binary-image#comment_897348

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/547905-converting-cartesian-coordinates-to-binary-image#comment_897348

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/547905-converting-cartesian-coordinates-to-binary-image#comment_897351

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/547905-converting-cartesian-coordinates-to-binary-image#comment_897351

Sign in to comment.