MATLAB Answers

Trying to change pixels in an image based on values I have obtained in a previous Array.

2 views (last 30 days)
Tim Murphy
Tim Murphy on 12 May 2020
Commented: Tim Murphy on 13 May 2020
I have a matrix that I have called IMAGE1 and consists of the following values:
[1225 534; 532 212; 1315 440; 39 1 ; 1542 503; 1509 902]
These values represent x and y positions of a satelite.
I am trying to create an image that has a black background and the above coordinates are red.
I have tried the following to accomplish this:
IMAGEPIC1 = zeros(1600)
IMAGEPic1(IMAGE1(:,1),IMAGE1(:,2)) = 1 %to change the pixels to red
figure,imshow(IMAGEPic1)
I end up with a black image with a grid of points because I believe Matlab is referencing every combination of IMAGE1's x and y values.
I have tried using sub2ind with no better results.
Is there a better way to produce an image with a black background and red pixels at the referenced coordinates?
Any help you can provide is appreciated.

  0 Comments

Sign in to comment.

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 13 May 2020
Edited: KALYAN ACHARJYA on 13 May 2020
image1=[1225 534;532 212;1315 440;39 1;1542 503;1509 902];
max1=max(image1(:));
image2=uint8(zeros(max1,max1);
image2(image1(:,1),image1(:,2))=255;
image2(:,:,2:3)=0;
imshow(image2);
%Please observe carefully, see red pixels

  1 Comment

Tim Murphy
Tim Murphy on 13 May 2020
Thank you for your help on this.
I tried the code that you provide, however I am still recieving the same grid image. By that I mean I get a red pixel at [1225 534] and [534 1225]. I tried a longer more tedious method where I have converted each X and Y coordinate to the element reference number using the code below:
IMAGE1Ref = (image1(:,1).*MaxY)- MaxY +(MaxY - image1(:,2))
Then using:
IMAGEPic1(IMAGE1Ref)=255;
IMAGEPic1(:,:,2:3)=0;
figure,imshow(IMAGEPic1);
This does provide a black background image with red pixels at each X and Y coordinate from image1.

Sign in to comment.

Products


Release

R2019a