Info

此问题已关闭。 请重新打开它进行编辑或回答。

Fill contour with specified color (on RGB image)?

2 次查看(过去 30 天)
I found the code below on matlab newsreader,, can I do it to RGB image?, if it possible to do,, can you help me how to fill contour with specified color on an RGB image??? need help,,,urgent,,,
here is the code:
fontSize = 15;
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Let's compute and display the histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(pixelCount);
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% Get a thresholded, binary image.
binaryImage = grayImage < 80;
% Display the binary image.
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Binary "Mask" Image', 'FontSize', fontSize);
% Average it with the image and put into the red channel
averageImage = (256 * single(binaryImage) + single(grayImage))/2;
redChannel = grayImage; % Initialize to same as gray.
% Make it reddish just where the mask is.
redChannel(binaryImage) = averageImage(binaryImage);
% Create the RGB image.
coloredImage = cat(3, redChannel, grayImage, grayImage);
% Display the binary image.
subplot(2, 2, 4);
imshow(coloredImage, []);
title('Colored Image', 'FontSize', fontSize);

回答(0 个)

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by