Image segmentation but 'edge' does not work
1 view (last 30 days)
Show older comments
i need this result, to outline it in red
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/827270/image.png)
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 Comments
Walter Roberson
on 23 Nov 2021
lungct = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/809364/lungCT.PNG');
size(lungct)
It is a color image.
Answers (2)
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);
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.
0 Comments
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.
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!