Removing the unwanted portion of image and keeping the center line

3 views (last 30 days)
I am currently working on fabric defect detection project. I have done the preprocessing and also the edge detection part. But after doing the edge detecting using roberts operator i found there is till lot of noise in my image as show below
1) Before prepreocessing
2) After preprocessing and edge detection:-
I have tried to use median filter operation in order to remove noise but it is also removing pixels from the are of interest (Center line(Idntfying double prick in images)) .
3) Median filtering
How can I solve this problem
Here is my code:-
close all;
clear all;
I=imread('fab_def.jpg');
I=rgb2gray(I);
I=medfilt2(I);
%I2=histeq(I);
figure;
imshow(I);
[M,N]=size(I);
%% ideal low pass filtering
F=fft2(I);
u=0:(M-1);
v=0:(N-1);
idx=find(u>M/2);
u(idx)=u(idx)-M;
idy=find(v>N/2);
v(idy)=v(idy)-N;
[V,U]=meshgrid(v,u);
D=sqrt(U.^2+V.^2);
%% filtering the image
P=max(max(F));
H=double(D<=P); % Comparing with the cut-off frequency
G=H.*F; % Convolution with the Fourier transformed image
g=real(ifft2(double(G))); % Inverse Fourier transform
figure;
imshow(I),figure,imshow(g,[ ]); % Displaying input and output image
%% Edge detection
I3=edge(g,'sobel');
figure;
imshow(I3);
I3=medfilt2(I3);
figure;
imshow(I3);
%% erosion and dilution
sel=strel('line',300,90);
I4=imclose(I3,sel);
figure;
imshow(I4);

Accepted Answer

yanqi liu
yanqi liu on 26 Sep 2021
Edited: yanqi liu on 26 Sep 2021
sir, may be use the follows to location the target
clc;
clear all;
close all;
I=imread('ceshi.jpg');
I=rgb2gray(I);
I=medfilt2(I);
%I2=histeq(I);
figure;
imshow(I);
[M,N]=size(I);
%% ideal low pass filtering
F=fft2(I);
u=0:(M-1);
v=0:(N-1);
idx=find(u>M/2);
u(idx)=u(idx)-M;
idy=find(v>N/2);
v(idy)=v(idy)-N;
[V,U]=meshgrid(v,u);
D=sqrt(U.^2+V.^2);
%% filtering the image
P=max(max(F));
H=double(D<=P); % Comparing with the cut-off frequency
G=H.*F; % Convolution with the Fourier transformed image
g=real(ifft2(double(G))); % Inverse Fourier transform
figure;
imshow(I),figure,imshow(g,[ ]); % Displaying input and output image
%% Edge detection
I3=edge(g,'sobel');
figure;
imshow(I3);
I4 = imclose(I3, strel('line', 15, 90));
I5 = imopen(I4, strel('line', 5, 0));
I5 = bwareaopen(I5, 200);
figure;
imshow(I5);
%% erosion and dilution
sel=strel('line',300,90);
I6=imclose(I5,sel);
figure;
imshow(I6);
I7 = I.*uint8(I6);
figure;
imshow(I7);

More Answers (1)

Image Analyst
Image Analyst on 22 Sep 2021
What I'd do is to first identify the big stripe and use it as a mask. Then use bwareafilt() on what's left. Untested code:
horizontalProfile = sum(mask, 1);
plot(horizontalProfile, 'b-');
grid on;
% Find stripe
threshold = 100; % Whatever you want.
inStripe = bwareafilt(horizontalProfile > threshold, 1);
stripeMask = false(size(mask));
leftCol = find(inStripe, 1, 'first');
rightCol = find(inStripe, 1, 'last');
stripeMask(:, leftCol : rightCol) = true;
% Create mask with stripe erased
mask2 = mask; % Initialize
mask2(stripMask) = false; % Erase
% Filter based on size.
smallestAllowableArea = 10; % Whatever you want.
mask2 = bwareafilt(mask2, [smallestAllowableArea, inf]);
% Now add back in stripe mask
mask2 = mask2 | (mask & stripeMask);

Community Treasure Hunt

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

Start Hunting!