Filter löschen
Filter löschen

How should I remove noise from the image which is marked in red color except the crack lines?

1 Ansicht (letzte 30 Tage)
clc;
clear;
close all;
%%step 1
image = imread('D:/canal images/crack.jpg');
%image = imread('C:/Users/Jainee/Documents/MATLAB/frame60.jpg');
figure
imshow(image);
%%step 2
gray = rgb2gray(image);
imshow(gray);
title('Gray Scale');
%%step 3
croped = imcrop(gray);
figure
imshow(croped);
title('Croped Image');
%%step 4
sharpen = imsharpen(croped,'Amount',3);
figure
imshow(sharpen);
title('Sharped Image');
%%step 5
se = strel('Line',100,90); %%create a disk-shaped structring element
% bothat = imsubtract(imadd(sharpen,imtophat(sharpen,se)),imbothat(sharpen,se)); %%applying bottom hat method
bothat=imbothat(sharpen,se);
figure
imshow(bothat);
title('Bottom Hat Method');
%%step 6
level = graythresh(bothat); %%return gary level of image
BW = im2bw(bothat,level); %%convert into binary
figure
imshow(BW);
title('Binary Image');
%%step 7
% % s1=size(BW);
% % for i=1:s1(1)
% % for j=1:s1(2)
% % bw6(i,j)=1-BW(i,j);
% % end
% % end
% % figure;
% % imshow(bw6);
% bw6= BW
bw5 = bwareaopen(BW,80,8);
figure
imshow(bw5)
%%title('Size range: 20-50 pixels')
bwt5=BW-bw5;
figure
imshow(bwt5);
se2=strel('disk',2);
%
bw6=imclose(bwt5,se2);
% bw16 = imerode(bw6,se2);
figure
imshow(bw6);
bw18=bw6;
si = size(croped);
for i=1:si(1)
for j=1:si(2)
if(bw18(i,j)==1)
new_image(i,j,1)=255;
new_image(i,j,2)=0;
new_image(i,j,3)=0;
else
new_image(i,j,:)=croped(i,j,:);
end
end
end
figure
imshow(new_image);
  2 Kommentare
John D'Errico
John D'Errico am 20 Feb. 2018
Please learn to format your code readably next time. I fixed it for you here.
When you paste in the code, select it as a block, then click on the "{} Code" button above the edit window. Your code will now be formatted as code, instead of an unreadable mess.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 21 Feb. 2018
I'd use regionfill() to fill in the red regions with the surrounding perimeter, kind of like it's smeared inward.

Community Treasure Hunt

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

Start Hunting!

Translated by