How do i find edges in true colored image
Show older comments
I need to extract red plane of true color image. Then need to apply 8 directions sobel mask on this red plane image. then need to perform sobel edge detection using threshold value.
This is need to repeat for blue and green plane image as well
Can anyone please guide me how can i do that in matlab.
I am able to extract true red plane image by keeping blue and green as 0.But inbut filter2 function doesnt work on this.
Answers (2)
Image Analyst
on 24 May 2012
This ought to give you a good start:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
workspace; % Make sure the workspace panel is showing.
fontSize = 14;
% Read in a standard MATLAB color demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'peppers.png';
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
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 4, 1);
imshow(rgbImage, []);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Display them
subplot(2,4,2);
imshow(redChannel);
title('Red Channel', 'FontSize', fontSize);
subplot(2,4,3);
imshow(greenChannel);
title('Green Channel', 'FontSize', fontSize);
subplot(2,4,4);
imshow(blueChannel);
title('Blue Channel', 'FontSize', fontSize);
% Compute Sobel Filters and threshold them
threshRed = 1;
threshGreen = 3;
threshBlue = 4;
[sobelRed threshRed] = edge(redChannel,'sobel');
[sobelGreen threshGreen] = edge(greenChannel,'sobel');
[sobelBlue threshBlue] = edge(blueChannel,'sobel');
% Display them
subplot(2,4,6);
imshow(sobelRed, []);
title('Sobel Filter on Red Channel', 'FontSize', fontSize);
subplot(2,4,7);
imshow(sobelGreen, []);
title('Sobel Filter on Green Channel', 'FontSize', fontSize);
subplot(2,4,8);
imshow(sobelBlue, []);
title('Sobel Filter on Blue Channel', 'FontSize', fontSize);
4 Comments
Deepak
on 24 May 2012
Image Analyst
on 24 May 2012
That's not an error, it's a warning. This snippet of code will help you to turn it off.
% Turn off this warning "Warning: Image is too big to fit on screen; displaying at 33% "
% To set the warning state, you must first know the message identifier for the one warning you want to enable.
% Right after your line of code generates the error,
% query the last warning to discover the warning identifier. For example:
% warnStruct = warning('query', 'last');
% messageID = warnStruct.identifier
% In the command window, this will show:
% messageID =
% MATLAB:concatenation:integerInteraction
% Pass that into the warning function:
warning('off', 'Images:initSize:adjustingMag');
Deepak
on 24 May 2012
Image Analyst
on 25 May 2012
uint8's clip when they go beyond 255. Cast to double before you add:
t3=(double(ta1)+double(ta2)+double(ta3)+double(ta4)+double(ta5)+double(ta6)+double(ta7)+double(ta8));
figure,imshow(t3, []); % Make sure you use [] to properly scale.
ankita taparia
on 10 Dec 2018
0 votes
Why have we done thresholding here? And if i want to apply a 3x3 sobel filter then what change is to be done in the code?
Categories
Find more on Display 2-D Images 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!