필터 지우기
필터 지우기

how is edge detection done in matlab??

조회 수: 3 (최근 30일)
AFFY
AFFY 2015년 3월 10일
댓글: Image Analyst 2015년 3월 13일
I need to remove the white part of the above image and retain the original image as it is. Is this process called edge detection? If so then by using canny edge detection I lose my color information while removing the white part because the resultant output image comes in binary form. How can it be done without losing the colors in the image?

답변 (1개)

Image Analyst
Image Analyst 2015년 3월 13일
No reason for edge detection at all. I continue to be surprised when image processing beginners thing that edge detection is the way to go just because there are edges in the scene. I mean, why use a more complicated method when simple thresholding will get you what you want.
binaryImage = grayImage < someThreshold;
Here's a full demo:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
%clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 14;
% Read in a standard MATLAB gray scale demo image.
folder = 'D:\Temporary Stuff';
baseFileName = 'Image (2).jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- 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 in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
[rows, columns, numberOfColorBands] = size(rgbImage);
% Crop between lines 1400 and 2400
rgbImage = imcrop(rgbImage, [1, 1400, columns, 1000]);
subplot(2, 2, 1);
imshow(rgbImage, [0 255]);
title('Original Image', 'FontSize', fontSize);
set(gcf, 'Name', 'Demo by Image Analyst');
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
% Take the min value of R, G, or B.
grayImage = min(rgbImage, [], 3);
subplot(2, 2, 2);
imshow(grayImage, []);
title('Gray scale Image', 'FontSize', fontSize);
% Threshold the image
binaryImage = grayImage < 250;
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
% Clean it up
binaryImage = imfill(binaryImage, 'holes'); % Fill holes.
binaryImage = bwareaopen(binaryImage, 20000); % Get rid of small blobs.
subplot(2, 2, 4);
imshow(binaryImage, []);
title('Cleaned Binary Image', 'FontSize', fontSize);
  댓글 수: 9
AFFY
AFFY 2015년 3월 13일
these are the errors. I could not make out the meaning. so i'm directly sending what i got in my command window.
??? Error using ==> iptcheckinput Function IMHIST expected its first input, I or X, to be two-dimensional.
Error in ==> imhist>parse_inputs at 281 iptcheckinput(a, {'double','uint8','int8','logical','uint16','int16','single','uint32', 'int32'}, ...
Error in ==> imhist at 59 [a, n, isScaled, top, map] = parse_inputs(varargin{:});
Error in ==> ExtractBiggestBlob at 41 [pixelCount, grayLevels] = imhist(grayImage);

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by