Image segmentation but 'edge' does not work

조회 수: 11 (최근 30일)
Matthew Worker
Matthew Worker 2021년 11월 22일
편집: John Kelly 2021년 12월 8일
i need this result, to outline it in red
but i keep getting this error message.
Error using activecontour>parse_inputs (line 381)
The 'edge' method is not supported for color or vector-valued images.
Error in activecontour (line 266)
[A, mask, N, method, smoothfactor,contractionbias] = parse_inputs(args{:});
i attached the image and my code. Thank you!!
lungct = imread('lungCT.png');
twodimimgg = im2double(lungct); %coverted to double
imshow(twodimimgg)
r = drawrectangle;
mask = createMask(r);
bw = activecontour(twodimimgg,mask,200,'edge');
hold on;
visboundaries(bw,'Color','r');
  댓글 수: 2
Walter Roberson
Walter Roberson 2021년 11월 23일
lungct = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/809364/lungCT.PNG');
size(lungct)
ans = 1×3
361 512 3
It is a color image.
Rena Berman
Rena Berman 2021년 12월 8일
(Answers Dev) Restored edit

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

답변 (2개)

Image Analyst
Image Analyst 2021년 11월 23일
Try this:
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 22;
lungct = imread('LungCT.png');
[rows, columns, numberOfColorChannels] = size(lungct)
fprintf('Original image : %d rows, %d columns, %d color channels.\n', rows, columns, numberOfColorChannels);
if numberOfColorChannels > 1
fprintf('The original image is true color RGB, 24 bits.\nNow we will convert it to gray scale...\n');
% Convert to gray scale.
lungct = rgb2gray(lungct);
% Update size.
[rows, columns, numberOfColorChannels] = size(lungct);
fprintf('Gray scale image : %d rows, %d columns, %d color channels.\n', rows, columns, numberOfColorChannels);
else
fprintf('The original image is gray scale: %d rows, %d columns, %d color channels.\n', rows, columns, numberOfColorChannels);
end
twodimimgg = im2double(lungct); % Convert to double
subplot(2, 2, 1);
imshow(twodimimgg, [])
title('Gray Scale Image', 'FontSize',fontSize)
g = gcf;
g.WindowState = 'maximized';
% Have user draw a rectangular ROI.
uiwait(helpdlg('Draw a rectangle over the image. Simply lift the mouse button to accept it.'))
r = drawrectangle;
mask = createMask(r);
subplot(2, 2, 2);
imshow(mask)
title('The mask you drew', 'FontSize',fontSize)
bw = activecontour(twodimimgg,mask,200,'edge');
subplot(2, 2, 3);
imshow(bw)
hold on;
visboundaries(bw,'Color','r');
title('Active Contours', 'FontSize',fontSize)
Tell me what you see printed in the command window.

DGM
DGM 2021년 11월 22일
The image is actually a 3-channel (RGB) image. You can flatten it:
lungct = imread('lungCT.png');
lungct = rgb2gray(lungct);
  댓글 수: 1
DGM
DGM 2021년 11월 23일
it works without error in R2019b.
If it's still giving you an error about color inputs, verify the size of the arguments passed to activecontour(). They should be 2D, not 3D.

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

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by