10 views (last 30 days)

Hi, I have a basic level of image processing/matlab. I need to write an m file to complete skeletisation of a binary image of the word "skeleton" in white on a black background. It is to be done without using matlab functions for skeletising. possibly one that will work on all binary images. Thanks

my code is as follows. I created it using an algorithm found online and adapted it to this:

clear all

I=imread('skeleton.jpg')

I = im2double(I);

I = im2bw(I);

figure, imshow(I);

H = size(I, 1); %height of image

W = size(I, 2); %width of image

for i = 2:H-1

for j = 2:W-1

Neighbour = [I(i-1,j) I(i-1,j+1) I(i,j+1) I(i+1,j+1) I(i+1,j) I(i+1,j-1) I(i,j-1) I(i-1,j-1)];

Surrounds = [I(i-1,j) I(i-1,j+1) I(i,j+1) I(i+1,j+1) I(i+1,j) I(i+1,j-1) I(i,j-1) I(i-1,j-1) I(i-1,j)];

Transition = nnz(diff(Surrounds)==1);

Non_zero = sum(Neighbour(:)==1);

if Transition==1 && (2<=Non_zero<=6) && (I(i-1,j)*I(i,j+1)*I(i+1,j)==0) && (I(i,j+1)*I(i+1,j)*I(i,j-1)==0)

I(i,j)=0;

end

end

end

figure, imshow(I)

Thomas
on 18 Apr 2013

The grassfire transform would be easy to implement: http://en.wikipedia.org/wiki/Grassfire_Transform

Be aware that this algorithm is not exceptionally fast. However, it can be parallelized.

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/72642-i-have-a-basic-level-of-image-processing-matlab-i-need-to-write-an-m-file-to-complete-skeletisation#comment_144108

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/72642-i-have-a-basic-level-of-image-processing-matlab-i-need-to-write-an-m-file-to-complete-skeletisation#comment_144108

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/72642-i-have-a-basic-level-of-image-processing-matlab-i-need-to-write-an-m-file-to-complete-skeletisation#comment_144112

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/72642-i-have-a-basic-level-of-image-processing-matlab-i-need-to-write-an-m-file-to-complete-skeletisation#comment_144112

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/72642-i-have-a-basic-level-of-image-processing-matlab-i-need-to-write-an-m-file-to-complete-skeletisation#comment_144117

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/72642-i-have-a-basic-level-of-image-processing-matlab-i-need-to-write-an-m-file-to-complete-skeletisation#comment_144117

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/72642-i-have-a-basic-level-of-image-processing-matlab-i-need-to-write-an-m-file-to-complete-skeletisation#comment_144126

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/72642-i-have-a-basic-level-of-image-processing-matlab-i-need-to-write-an-m-file-to-complete-skeletisation#comment_144126

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/72642-i-have-a-basic-level-of-image-processing-matlab-i-need-to-write-an-m-file-to-complete-skeletisation#comment_144130

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/72642-i-have-a-basic-level-of-image-processing-matlab-i-need-to-write-an-m-file-to-complete-skeletisation#comment_144130

Sign in to comment.