I have an image with different kind of edges. But I want to detect the edges of black color. I have intended to so by using convolution. I need suggestions for the kernel filter.
MATLAB: How to detect black edges only using sobel or matched filter
digital image processingedge detection
Related Solutions
I ran this on my 8-core machine using R2009a:
function myFilterTestx = rand(1e6, 8);x1 = x(:,1);x2 = x(:,2); x3 = x(:,3);x4 = x(:,4); x5 = x(:,5);x6 = x(:,6); x7 = x(:,7);x8 = x(:,8); [B, A] = butter(3, 0.2, 'low');tic;for i=1:100 y = filter(B, A, x); % Matrix
% clear('y'); % Avoid smart JIT interferences => same effects!
endtoctic;for i=1:100 y1 = filter(B, A, x1); % Eight vectors
y2 = filter(B, A, x2); y3 = filter(B, A, x3); y4 = filter(B, A, x4); y5 = filter(B, A, x5); y6 = filter(B, A, x6); y7 = filter(B, A, x7); y8 = filter(B, A, x8); % clear('y1', 'y2'); % No qualitative changes
endtoc
clear all;
And got this:
Elapsed time is 16.865596 seconds. Elapsed time is 16.117599 seconds.
Only one core was active during each test.
I ran this on my 8-core machine using R2011a and got:
Elapsed time is 12.542615 seconds.Elapsed time is 16.268821 seconds.
All eight cores were active for the first test (on the matrix) and only a single core for the seconds test (on individual vectors).
I added this to the bottom of the test:
y_par = zeros(size(x));matlabpool(8);tic; parfor j = 1:8 for i=1:100 y_par(:,j) = filter(B, A, x(:,j)); end % clear('y_par'); % No qualitative changes
endtoc; matlabpool close;
And got this when using R2011a:
Elapsed time is 13.305009 seconds.Elapsed time is 16.398203 seconds.Starting matlabpool using the 'local' configuration ... connected to 8 labs.Elapsed time is 3.542021 seconds.Sending a stop signal to all the labs ... stopped.
No, you're doing it all wrong. I started to try to fix your code, but it's better to just start from scratch and do it the right way from step 1. Here, try this way, using imgradient():
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.
format longg; format compact; fontSize = 20; % Read in RGB image.
rgbImage=imread('onion.png'); % Display image.
subplot(3,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 images.
subplot(3,4, 2); imshow(redChannel); title('Red Image', 'FontSize', fontSize); subplot(3,4, 3); imshow(greenChannel); title('Green Image', 'FontSize', fontSize); subplot(3,4, 4); imshow(blueChannel); title('Blue Image', 'FontSize', fontSize); % Apply Sobel filters:
sobelFilteredImageR = imgradient(redChannel); sobelFilteredImageG = imgradient(greenChannel); sobelFilteredImageB = imgradient(blueChannel); % Combine them all so we can add to original
colorSobel = cat(3, sobelFilteredImageR, sobelFilteredImageG, sobelFilteredImageB); % Display images. subplot(3,4, 6); imshow(sobelFilteredImageR, []); title('Red Sobel Image', 'FontSize', fontSize); subplot(3,4, 7); imshow(sobelFilteredImageG, []); title('Green Sobel Image', 'FontSize', fontSize); subplot(3,4, 8); imshow(sobelFilteredImageB, []); title('Blue Sobel Image', 'FontSize', fontSize); % Add together with three different weightings.
weighting = 0.1; outputImage = rgbImage + uint8(weighting * colorSobel); subplot(3,4, 9); imshow(outputImage); caption = sprintf('Weighting of %.2f', weighting); title(caption, 'FontSize', fontSize); weighting = 0.4; outputImage = rgbImage + uint8(weighting * colorSobel); subplot(3,4, 10); imshow(outputImage); caption = sprintf('Weighting of %.2f', weighting); title(caption, 'FontSize', fontSize); weighting = 0.7; outputImage = rgbImage + uint8(weighting * colorSobel); subplot(3,4, 11); imshow(outputImage); caption = sprintf('Weighting of %.2f', weighting); title(caption, 'FontSize', fontSize); weighting = 1.0; outputImage = rgbImage + uint8(weighting * colorSobel); subplot(3,4, 12); imshow(outputImage); caption = sprintf('Weighting of %.2f', weighting); title(caption, 'FontSize', fontSize);
Best Answer