Clear Filters
Clear Filters

Image segmentation but 'edge' does not work

2 views (last 30 days)
Matthew Worker
Matthew Worker on 22 Nov 2021
Edited: John Kelly on 8 Dec 2021
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
r = drawrectangle;
mask = createMask(r);
bw = activecontour(twodimimgg,mask,200,'edge');
hold on;
Walter Roberson
Walter Roberson on 23 Nov 2021
lungct = imread('');
ans = 1×3
361 512 3
It is a color image.

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 23 Nov 2021
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);
fprintf('The original image is gray scale: %d rows, %d columns, %d color channels.\n', rows, columns, numberOfColorChannels);
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);
title('The mask you drew', 'FontSize',fontSize)
bw = activecontour(twodimimgg,mask,200,'edge');
subplot(2, 2, 3);
hold on;
title('Active Contours', 'FontSize',fontSize)
Tell me what you see printed in the command window.

DGM on 22 Nov 2021
The image is actually a 3-channel (RGB) image. You can flatten it:
lungct = imread('lungCT.png');
lungct = rgb2gray(lungct);
  1 Comment
DGM on 23 Nov 2021
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!