Simplified Image Processing

I am trying to use the douglas-peucker to simplify connected components. I get my connected components using bwlabel and I submit it to the douglas algorithm. Here is a link to the algorithm I'm using, Douglas-Peucker Matlab Algorithm

Here is my code -

 clc; image=imread('mmm1.jpg'); image = im2bw(image); [imx imy]=size(image); n1=zeros(imx,imy); I=zeros(imx,imy); L = bwlabel(image,8) ;%Calculating connected components [r,c] = find(L==1); %Using 1st connected component n1=zeros(imx,imy); rc = [rc]; [ps mm] = dpsimplify(rc,1); %Douglas-Peucker algorithm %To display original component %___________________________________________________________________ [sx sy]=size(rc); for j=1:sx x1=rc(j,1); y1=rc(j,2); n1(x1,y1)=1; end figure,imshow(n1); %___________________________________________________________________ %To display component after simplification n1=zeros(imx,imy); [sx sy]=size(mm); for j=1:sx x1=rc(j,1); y1=rc(j,2); n1(x1,y1)=1; end figure,imshow(n1); 

This was my original source image - enter image description here

This was my 1st component, to which I applied the douglas-peucker -

enter image description here

It was the result of an algorithm - enter image description here

Douglas-Peucker code can be found in the link mentioned above. So My question is Why does simplification not happen for the whole component? How can i fix this?

+5
source share
1 answer

I believe that you want to determine how many segments of a straight line are in the image. I did something similar to a morphological hit and was able to segment these lines, although not fully.

I prepared a vertical line structuring (SE) element, and then created two more SEs, rotating it 60 and 120 degrees around my center. I blew the source image with these SEs and then got connected components.

 im = imread('IWVlt.jpg'); bw = im2bw(im, graythresh(im)); % SEs w = 15; line = zeros(w); line(:, round(w/2)) = 1; bw1 = zeros(size(bw)); for i = 1:3 bw1 = bw1 + imerode(bw, line); line = imrotate(line, 60, 'nearest'); end [lbl, n] = bwlabel(bw1, 8); figure, imshow(bw1) figure, imshow(label2rgb(lbl)) 

As a result, I get 25 components. By changing w in your code, you can minimize the error. bonds

With w = 9, which is the smallest value of w that can take when all segments are detected, I get 26 components. You can filter out too small components. bonds2

+2
source

All Articles