필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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
John D'Errico
John D'Errico 2018년 2월 20일
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.

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

답변 (1개)

Image Analyst
Image Analyst 2018년 2월 21일
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