Remi Moore
Remi Moore

Reputation: 35

matlab - Object detection

the following image is given

1

And I have to detect the the components at the bottom right of the image. the result should look something like this:

2

thresholding followed by erosion look like this in code:

clc; close all;
I  = imread('Leiterplatte.png');
se = strel('rectangle', [2 4]);
Ie1 = imerode(I,se);
imshow(I);

%figure; histogram(I)
Im = Ie1>40 & Ie1<128;
figure; imshow(Im) 

se = strel('rectangle', [8 8]);
Ie = imerode(Im,se);

figure; imshow(Ie)

I(Ie)=255;
figure; imshow(I)

And I get the following result:

enter image description here

but the detected rectangles are either too small or if not then the spots are still in the image like so:

enter image description here

Upvotes: 0

Views: 178

Answers (1)

saastn
saastn

Reputation: 6015

You are almost there. A little play with constants and an imopen call to remove spots will get the job done:

I  = imread('RuaDN.png');
se = strel('rectangle', [4 8]);
Ie1 = imerode(I,se);
Im = Ie1>70 & Ie1<130;
se = strel('rectangle', [8 16]);
Ie = imopen(Im, se);

O = I;
O(Ie) = 255;

enter image description here

Upvotes: 2

Related Questions