Image segmentation but 'edge' does not work

11 次查看(过去 30 天)
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.

请先登录,再进行评论。

回答(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