|
On Aug 10, 7:29 pm, "Mathew Thomas" <mathe...@gmail.com> wrote:
> Hello everyone,
>
> I have a color image and want to find the edges. The image has two colors - black n brown... I only want to find the edges of the brown portion. How can I do this ?? I tried thresholding, but I guess I could not apply it right...Any help is welcome..
>
> Thank you,
>
> Matt
----------------------------------------------------------------------------------------------------------------
Matt:
Try this demo:
Good luck,
ImageAnalyst
% Demo macro to outline brown regions.
% by ImageAnalyst
clc;
close all;
workspace;
rgbImage = uint8(zeros([200 200 3]));
rgbImage(60:120, 60:120, 1) = 150;
rgbImage(60:120, 60:120, 2) = 80;
subplot(3,1,1);
imshow(rgbImage);
title('Original image.');
% Find brown. Since the only other color is black [0, 0, 0],
% brown will be anyplace that is non-zero.
% But for generality, let's look for red between 120 and 180
% and for green between 50 and 100.
inRedRange = rgbImage(:,:, 1) > 120 & rgbImage(:,:, 1) < 180;
inGreenRange = rgbImage(:,:, 2) > 50 & rgbImage(:,:, 2) < 100;
% AND them together to find where they're both true.
binaryImage = inRedRange & inGreenRange;
subplot(3,1, 2);
imshow(binaryImage, []);
title('Thresholded image.');
% Now find the boundaries
[boundaries, labeledImage] = bwboundaries(binaryImage,'noholes');
% Display them over the original image.
subplot(3,1, 3);
imshow(rgbImage);
hold on; % Don't let plot() blow away our image.
title('Original image with boundaries.');
for k = 1:length(boundaries)
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'w', 'LineWidth', 2)
end
% Maximize window.
set(gcf, 'Position', get(0, 'ScreenSize')); % Maximize figure.
|