gradient magnitude image

  • Follow


Hey everyone,

I met a problem when using the Prewitt edge detector to obtain a gradient magnitude image. my code is: 

Igm = edge(I,'prewitt');%I is a gray image

The result is a binary edge. But I need a gray image of gradient magnitude instead of the edge.  Can anybody tell me which function shall I use?

Thank you~

Chang
0
Reply Chang 12/10/2010 5:46:05 PM

imfilter().
0
Reply ImageAnalyst 12/10/2010 5:47:32 PM


ImageAnalyst <imageanalyst@mailinator.com> wrote in message <f0a7e9de-2395-4f24-9031-2da7a3d28aa8@j1g2000vbl.googlegroups.com>...
> imfilter().

thank you~ but can you give me a more detail answer. how to code it ?
I referred the help file and imfilter() has no relationship with prewitt... 
0
Reply Chang 12/10/2010 6:51:05 PM

Chang Qin:
Not sure what the difficulty was - it's simply two lines of code:
% Get a vertical Prewitt filter kernel:
prewittKernelV = [-1 -1 -1; 0 0 0; 1 1 1];
% Do the filtering.
outputImageV = imfilter(grayImage, prewittKernelV, 'same');


Nonetheless, here's a full tutorial:
IMPORTANT: The newsreader may break long lines into two
Be sure to join any long lines that got split into multiple single
lines.
These can be found by the red lines on the left side of your
text editor, which indicate syntax errors, or else just run the
code and it will stop at the split lines with an error.

% function test()
clc;    % Clear the command window.
close all;  % Close all figures (except those of imtool.)
imtool close all;  % Close all imtool figures.
clear;  % Erase all existing variables.
workspace;  % Make sure the workspace panel is showing.
fontSize = 20;

% Change the current folder to the folder of this m-file.
if(~isdeployed)
	cd(fileparts(which(mfilename)));
end

% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Program Files\MATLAB\R2010a\toolbox\images\imdemos';
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
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')

% Cast to floating so we can see both + and - edges.
grayImage = single(grayImage);

% Get a vertical Prewitt filter kernel:
prewittKernelV = [-1 -1 -1; 0 0 0; 1 1 1];
% Do the filtering.
outputImageV = imfilter(grayImage, prewittKernelV, 'same');
% Display the original gray scale image.
subplot(2, 2, 2);
imshow(outputImageV, []);
title('Vertical Prewitt Filtered Image', 'FontSize', fontSize);

% Get a vertical Prewitt filter kernel:
prewittKernelH = [-1 0 1; -1 0 1; -1 0 1];
% Do the filtering.
outputImageH = imfilter(grayImage, prewittKernelH, 'same');
% Display the original gray scale image.
subplot(2, 2, 4);
imshow(outputImageH, []);
title('Horizontal Prewitt Filtered Image', 'FontSize', fontSize);

outputImageG = uint8(sqrt(single(outputImageH).^2 +
single(outputImageV).^2));
% Display the original gray scale image.
subplot(2, 2, 3);
imshow(outputImageG, []);
title('Both Prewitt Filtered Image', 'FontSize', fontSize);

0
Reply ImageAnalyst 12/10/2010 7:44:26 PM

3 Replies
714 Views

(page loaded in 0.04 seconds)

Similiar Articles:













7/23/2012 6:37:49 AM


Reply: