Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Fill contour with specified color (on RGB image)?

조회 수: 1 (최근 30일)
UNHAS HASANUDDIN
UNHAS HASANUDDIN 2011년 8월 18일
마감: Walter Roberson 2017년 1월 3일
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