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

1 回表示 (過去 30 日間)
Tim Murphy
Tim Murphy 2020 年 5 月 12 日
コメント済み: Tim Murphy 2020 年 5 月 13 日
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.

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 5 月 13 日
編集済み: KALYAN ACHARJYA 2020 年 5 月 13 日
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 件のコメント
Tim Murphy
Tim Murphy 2020 年 5 月 13 日
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.

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

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by