Does anyone know of a julia package that can generate vectors/polygons (i,j) for the boundaries of areas found within a BitMatrix.
your question doesn’t quite make sense, can you give people an example input output?
Given a BitArray M:
M = falses(5,5)
M[2, 2:3] .= true
julia> M
5×5 BitMatrix:
0 0 0 0 0
0 1 1 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
I want the polygon(s) enclosing the true values in M
j = [1.5, 2.5, 3.5, 3.5. 2.5, 1.5, 1.5]
i = [1.5, 1.5, 1.5, 2.5. 2.5, 2.5, 1.5]
My guess is that something like this would be used frequently in image segmentation
We have vectorization (or polygon tracing) in the GeoStats.jl stack, take a look at the Potrace transform:
using GeoStats
help?> Potrace
search: Potrace ExponentialVariogram
Potrace(col; [ϵ])
Trace polygons on 2D image data with Selinger's Potrace algorithm.
The categories stored in column col are converted into binary masks, which are
then traced into multi-polygons. When provided, the option ϵ is forwarded to the
[Selinger[@ref] simplification algorithm.
References
============
• Selinger, P. 2003. Potrace: A polygon-based tracing algorithm
(https://potrace.sourceforge.net/potrace.pdf)
It will return a Meshes.jl geometry with all the related functionality.
MWE:
using GeoStats
gdata = georef((mask=mask,))
gdata |> Potrace(:mask)
Fantastic, exactly what I was looking for. Thanks!
@juliohm can we please have this algorithm in ImageBinarization.jl too? Potrace is very useful raster-to-vector converter
@Ashwani_Rathee ImageBinarization.jl has a different goal. Potrace returns Meshes.jl geometries, not images of 0s and 1s.
I know ImageBinarization.jl has a different goal but it could be a good utility function for use in future. I remember utilizing potrace-js for converting raster image to its vector state. I utilized this to convert a brain tumor mask to its path as shown here: MHacks 21: Brain Tumor Segmentation Annotation tool - YouTube. So I think it could be a good addition to the set of algorithms we provide. Ofcourse we might need to adapt it to suit ImageBinarization.jl better.
It is a matter of scope and software design. A package for binarization should not contain a function for vectorization and vice-versa. Also, our implementation is tightly integrated with the Meshes.jl/GeoStats.jl stack, it relies on types that other stacks don’t have.
potrace
has been in my TODO list for a long time to try to reproduce the service provided by https://vectormagic.com/
We can kind of say then that it’s a useful tool to have?