JuliaImages / ImageSegmentation.jl

Partitioning images into meaningful regions
Other
47 stars 23 forks source link

proposal: add SLIC superpixel algorithm #53

Open Cuda-Chen opened 3 years ago

Cuda-Chen commented 3 years ago

Recently, I wrote a SLIC superpixel algorithm in pure Julia. For watching this repo almost a year, I found there was no one add SLIC into ImageSegmentation.jl. Therefore, I would like to add my implementation, though it needs a lot of reworking to fit into.

johnnychen94 commented 3 years ago

There's a WIP PR https://github.com/johnnychen94/SuperPixels.jl/pull/2 that I failed to continue because I'm unsure how to enforce pixel connectivity when I wrote that. If you're interested, could you help finish that part?

I've introduced a SuperPixel struct to make post-processing easier there.

Cuda-Chen commented 3 years ago

@johnnychen94 I think I can give it a try :)

By the way, will prune_segments be a good start of enforce connectivity?

johnnychen94 commented 3 years ago

By the way, will prune_segments be a good start of enforce connectivity?

Probably! TBH I'm don't have much knowledge of image segmentation, I suggest we follow the original implementation unless we know what's actually happening there.

Ha, I just saw your note that "Current I do not implement enforce connectivity part." 😄

Cuda-Chen commented 3 years ago

OK, I will realize how the original implementation does on enforce connectivity. And we can watch how PSMM does on enforce connectivity, too.

johnnychen94 commented 3 years ago

And we can watch how PSMM does on enforce connectivity, too.

Yes, it could be a good recourse, the only issue is that PSMM doesn't have a license file. We may need to list it as a reference if you find it useful.

On the other hand, scikit-image is a better resource as it has a clear license (Modified BSD).

Cref: https://github.com/JuliaImages/ImageFiltering.jl/pull/81#issuecomment-429640026

Cuda-Chen commented 3 years ago

After reading your comment, I have to admit my SLIC implementation in Julia have reference laixintao's work.

I have added the reference in my Julia SLIC repo as a good practice.

jsundram commented 3 years ago

Is this work still in progress? Or do folks just use https://github.com/johnnychen94/SuperPixels.jl for SLIC?

johnnychen94 commented 3 years ago

Still in WIP, I need to work through https://github.com/johnnychen94/SuperPixels.jl/pull/6 first to find out what the best type design is in Julia. Hopefully, we could work on ImageSegmentation.jl to merge everything in SuperPixels.jl.

FYI, with @Cuda-Chen's help, a working SLIC version is available in the analyze branch (https://github.com/johnnychen94/SuperPixels.jl/blob/analyze/src/analyze.jl), it's usable but I'm not satisfied with the internal type design in SuperPixels and I plan to rework it entirely so I haven't make a release yet.

jsundram commented 3 years ago

Thanks @johnnychen94! This code works for me -- I wonder if you are open to just having _slic return a SegmentedImage type (which is what the rest of ImageSegmentation.jl returns)? I've reworked the code in analyze branch to do that . . . it looks as follows (see the SegmentedImage function at the bottom of the file)

https://gist.github.com/jsundram/e78bc63cb131fb66cb7c811bdd9a3e0e