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

2 vues (au cours des 30 derniers jours)
Alberto Acri
Alberto Acri le 31 Jan 2023
Réponse apportée : Voss le 31 Jan 2023
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)

Réponse acceptée

Voss
Voss le 31 Jan 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)

Plus de réponses (0)

Catégories

En savoir plus sur Contour Plots dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by