How can I crop selected portion of an image and place it in a white background?

조회 수: 2 (최근 30일)
I am trying to modify a code for watershed method segmentation, and the output figure is this. However, I want to subplot another image in this figure with only the tumor within the boundary in a blank background. How can I do it?

채택된 답변

Image Analyst
Image Analyst 2021년 5월 21일
Try this:
subplot(2, 1, 1);
% Display RGB image with yellow boundary burned into it.
imshow(rgbImage); % or display the gray scale image then call hold on and then call plot(xYellow, yYellow, 'y-', 'LineWidth', 3)
subplot(2, 1, 2);
% Mask the image using bsxfun() function to multiply the mask by each channel individually. Works for gray scale as well as RGB Color images.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));
imshow(maskedRgbImage);
If you don't have mask, you can get it from the coordinates of the yellow boundary
[rows, columns, numberOfColorChannels] = size(rgbImage);
mask = poly2mask(xYellow, yYellow, rows, columns);
  댓글 수: 1
Tawsif Mostafiz
Tawsif Mostafiz 2021년 5월 21일
Thank you very much. It works! But the background is still black. I know it may be a silly question, but how doI turn it into white?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Tawsif Mostafiz
Tawsif Mostafiz 2021년 5월 22일
Nevermind, found it!

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by