Color in white only pixels defined by a matrix [rx2]

2 ビュー (過去 30 日間)
Alberto Acri
Alberto Acri 2023 年 1 月 31 日
回答済み: Voss 2023 年 1 月 31 日
Hi! I would like to keep white pixels only at the desired coordinates ("contour") while transforming other pixels with black color. Is there an easy way to be able to do this?
BW = imread('blobs.png');
imshow(BW)
r1 = 163;
c1 = 37;
contour = bwtraceboundary(BW,[r1 c1],'W');
hold on
plot(contour(:,2),contour(:,1),'g','LineWidth',2)

採用された回答

Voss
Voss 2023 年 1 月 31 日
BW = imread('blobs.png');
imshow(BW)
r1 = 163;
c1 = 37;
contour = bwtraceboundary(BW,[r1 c1],'W');
hold on
plot(contour(:,2),contour(:,1),'g','LineWidth',2)
figure
BW_new = BW; % make a copy of BW
BW_new(:) = 0; % set all pixels to black
BW_new(sub2ind(size(BW),contour(:,1),contour(:,2))) = 1; % set "contour" pixels to white
imshow(BW_new)

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by