Skeletonize with Igor V6
Djebulon
I need to find a way to extract the skeleton of a stack of images (tiff files with 100 layers) automaticaly (1 skeleton image for each layer of the stack).
Is there a native function or a plugin in Igor V6 to perform a skeletonization ?
Thank you in advance.
I put 2 images here, one is the original image (1 layer of a stack), the second is the skeleton of the first image (made with ImageJ manualy)
To accomplish this task you need to loop over the layers of the stack, extract an image, convert it (possibly from color) to binary and then perform thinning filter on the image. I have just make changes to the thinning filter in IP6 so before you try the code below you should download the latest (http://www.wavemetrics.net/Downloads/latest/).
Wave inStack
Variable iterations,isColor=0
if(DimSize(inStack,3)>0)
iterations=DimSize(inStack,3)
isColor=1
else
iterations=DimSize(inStack,2)
endif
Variable i
// Create an output wave of type unsigned byte:
Make/B/U/O/N=(DimSize(inStack,0),DimSize(inStack,1),iterations) skelWave=0
if(isColor==0)
for(i=0;i<iterations;i+=1)
ImageTransform/P=(i) getPlane inStack
Wave M_ImagePlane
// apply threshold to the grayscale image:
ImageThreshold/Q/M=1 M_ImagePlane
Wave M_ImageThresh
// apply thinning:
MatrixFilter /T/B=0 thin M_ImageThresh
Wave M_MatrixFilter
ImageTransform/P=(i) /D=M_MatrixFilter setPlane skelWave
endfor
else
for(i=0;i<iterations;i+=1)
ImageTransform/CHIX=(i) getChunk inStack
Wave M_Chunk
ImageTransform rgb2gray M_Chunk
Wave M_RGB2Gray
// apply threshold to the grayscale image:
ImageThreshold/Q/M=1 M_RGB2Gray
Wave M_ImageThresh
// apply thinning:
MatrixFilter /T/B=0 thin M_ImageThresh
Wave M_MatrixFilter
ImageTransform/P=(i) /D=M_MatrixFilter setPlane skelWave
endfor
endif
// cleanup:
KillWaves/Z M_MatrixFilter,M_ImageThresh,M_RGB2Gray,M_Chunk
End
I hope this helps,
A.G.
WaveMetrics, Inc.
January 7, 2015 at 11:54 am - Permalink
I updated my version and I will try this thinning module as soon as possible.
Thank you again
January 9, 2015 at 02:18 am - Permalink
I managed to build a stack of skeleton for my image.
But in the result I have more than just one contour. There are a lot of segments and dots.
Is there a way to remove these segments and dots and to keep only one contour ?
Thank you very much for your answer !! :)
The attached file is a .tiff (.jpg has been added)
January 15, 2015 at 08:36 am - Permalink
The skeleton algorithm does not attempt to generate a contour. It computes a skeleton for each apparent object within the image. If your image produces fragile/discontinuous contour you can improve the results by smoothing the data before computing the skeleton and/or by removing some of the short segments using morphological operators (see ImageMorphology).
A.G.
WaveMetrics, Inc.
January 15, 2015 at 11:03 am - Permalink