Can anyone help in explaining how the below code is detecting rain streaks???

clc
clear all
close all
I=imread('heavyrain.jpg');
%I=imresize(I,[512 512]);
I2=rgb2gray(I)
BW2 = bwmorph(I2,'remove');
%figure,imshow(BW2)
%title('figure1:bwmorph remove')
BW3 = bwmorph(I2,'skel',Inf);
%figure,imshow(BW3)
%title('figure:2 bwmorph inf')
SE = strel('arbitrary',eye(5));
BW2 = imerode(I2,SE);
figure,imshow(BW2)
title('figure:3 imerode')
BW3 = imdilate(BW2,SE);
figure,imshow(BW3)
title('figure:4 imdilate')
closeBW = imclose(BW3,SE);
figure, imshow(closeBW)
title('figure:5 imclose')
hy = fspecial('sobel');
hx = hy';
Iy = imfilter(double(I), hy, 'replicate');
Ix = imfilter(double(I), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
Iobrd = imdilate(BW2, SE );
Iobrcbr = imreconstruct(imcomplement(Iobrd), imcomplement(closeBW));
Iobrcbr = imcomplement(Iobrcbr);
figure, imshow(Iobrcbr)
title('figure:6 imcomplement')
fgm = imregionalmax(Iobrcbr);
figure, imshow(fgm)
title('figure:7 imregionalmax')
I2 = I;
I2(fgm) = 200;
figure, imshow(I2)
title('figure:8 fgm')
se2 = strel(ones(5,5));
fgm2 = imclose(fgm, se2);
fgm3 = imerode(fgm2, se2);

3 commentaires

Image Analyst
Image Analyst le 30 Sep 2017
Modifié(e) : Image Analyst le 30 Sep 2017
After you format it, someone might be able to: http://www.mathworks.com/matlabcentral/answers/13205#answer_18099 In short, highlight your code, then click the "{}Code" button.
clc
clear all
close all
I=imread('heavyrain.jpg');
%I=imresize(I,[512 512]);
I2=rgb2gray(I)
BW2 = bwmorph(I2,'remove');
%figure,imshow(BW2)
%title('figure1:bwmorph remove')
BW3 = bwmorph(I2,'skel',Inf);
%figure,imshow(BW3)
%title('figure:2 bwmorph inf')
SE = strel('arbitrary',eye(5));
BW2 = imerode(I2,SE);
figure,imshow(BW2)
title('figure:3 imerode')
BW3 = imdilate(BW2,SE);
figure,imshow(BW3)
title('figure:4 imdilate')
closeBW = imclose(BW3,SE);
figure, imshow(closeBW)
title('figure:5 imclose')
hy = fspecial('sobel');
hx = hy';
Iy = imfilter(double(I), hy, 'replicate');
Ix = imfilter(double(I), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
Iobrd = imdilate(BW2, SE );
Iobrcbr = imreconstruct(imcomplement(Iobrd), imcomplement(closeBW));
Iobrcbr = imcomplement(Iobrcbr);
figure, imshow(Iobrcbr)
title('figure:6 imcomplement')
fgm = imregionalmax(Iobrcbr);
figure, imshow(fgm)
title('figure:7 imregionalmax')
I2 = I;
I2(fgm) = 200;
figure, imshow(I2)
title('figure:8 fgm')
se2 = strel(ones(5,5));
fgm2 = imclose(fgm, se2);
fgm3 = imerode(fgm2, se2);
Can anyone explain the code if possible??
We have no idea what your background is or your understanding of computing is. We would therefore need to start with the basics of computing and write several textbooks worth of information to be sure that we have explained all aspects of the code that you might be having difficulty with. Even if we were willing to go through that effort, it would take a few years of our time. Are you sure that you have the time to wait?

Connectez-vous pour commenter.

Réponses (1)

OCDER
OCDER le 1 Oct 2017
Modifié(e) : OCDER le 1 Oct 2017
clc % clear command window
clear all % clear all variables
close all % close all figures
I=imread('heavyrain.jpg'); % read the image heavyrain.jpg
%I=imresize(I,[512 512]); % resize image, NOT - it's commented so useless code (code hoarding)
I2=rgb2gray(I); %rgb-to-gray conversion
BW2 = bwmorph(I2,'remove'); %black white morph image processing with some setting
%figure,imshow(BW2) % commented code (code hoarding)
%title('figure1:bwmorph remove') % commented code (code hoarding)
BW3 = bwmorph(I2,'skel',Inf); % another bwmorph with a different setting
%figure,imshow(BW3) %commented code (code hoarding)
%title('figure:2 bwmorph inf') %commented code (code hoarding)
SE = strel('arbitrary',eye(5)); % create morphological structuring matrix
BW2 = imerode(I2,SE); % erode image with SE
figure,imshow(BW2) % figure, image show
title('figure:3 imerode') %title
BW3 = imdilate(BW2,SE); % dilate image with Se
figure,imshow(BW3) % figure, image show
title('figure:4 imdilate') %title
closeBW = imclose(BW3,SE); %image close operation with SE
figure, imshow(closeBW) % figure, image show
title('figure:5 imclose') % title
hy = fspecial('sobel'); % a special function for 2-D filter
hx = hy'; % transpose
Iy = imfilter(double(I), hy, 'replicate'); % some image filtering
Ix = imfilter(double(I), hx, 'replicate'); % some image filtering
gradmag = sqrt(Ix.^2 + Iy.^2); % some math
Iobrd = imdilate(BW2, SE ); % some image dilation
Iobrcbr = imreconstruct(imcomplement(Iobrd), imcomplement(closeBW)); % some image reconstruction
Iobrcbr = imcomplement(Iobrcbr); % some image complement
figure, imshow(Iobrcbr) % figure, image show
title('figure:6 imcomplement') % title
fgm = imregionalmax(Iobrcbr); % something you should look up via "help imregionalmax"
figure, imshow(fgm) % figure, image show
title('figure:7 imregionalmax') % title
I2 = I; % copy variable I
I2(fgm) = 200; % set fgm to 200 for some reason
figure, imshow(I2) % figure, image show
title('figure:8 fgm') % title
se2 = strel(ones(5,5));
fgm2 = imclose(fgm, se2); % image closure
fgm3 = imerode(fgm2, se2); % image erosion
%Somewhere, raindrops were detected...

2 commentaires

Once rain streaks are detected the how to use neighborhood pixel technique to replace the vale of rain affected pixel with non rain detected???? any example????

Connectez-vous pour commenter.

Commenté :

le 2 Oct 2017

Community Treasure Hunt

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

Start Hunting!

Translated by