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

2 visualizzazioni (ultimi 30 giorni)
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)

Risposta accettata

Voss
Voss il 31 Gen 2023
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)

Più risposte (0)

Categorie

Scopri di più su Contour Plots in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by