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 CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by