algy / fast-slic Goto Github PK
View Code? Open in Web Editor NEW20x Real-time superpixel SLIC Implementation with CPU
License: MIT License
20x Real-time superpixel SLIC Implementation with CPU
License: MIT License
I assume that dissection of the image starts with a default honeycomb pattern which is later shape-optimized to minimize some function.
Is it possible to specify the initial pattern or to rotate it by 30 degrees?
After following the instructions to pip install fast_slic, copy and paste the beginner code for testing, then run into this error caused by "from fast_slic import Slic":
ImportError: cannot import name 'Slic' from partially initialized module 'fast_slic' (most likely due to a circular import)
Can someone tell me how to solve it?
I am using anaconda on win10. Thanks!
I am trying to use fast-slic
via a poetry dependency. This fails because it is not compatible with PEP 517.
This can be reproduced via pip install --no-cache-dir --use-pep517 fast-slic
.
Hi @Algy ,
Great work on the fast SLIC algorithm, the speed gain compared with scikit-image's SLIC is amazing.
I was wondering if there is a way of running the algorithm in zero-parameter mode (SLIC0).
The README does not include code example of how to generate and save the color result with the superpixles overlayed on the fish image. How can this be done?
Hi,
Thank you for your amazing slic implementation
In my project I have available a mask and I would like to apply the segmentation only to the pixels belonging to this mask.
I was wondering if support for masks (https://github.com/benjaminirving/maskSLIC) can be easily implemented.
Best,
Alessio
I don't know what the meaning of 'num_members' and ’color‘ in 'slic.slic_model.clusters'.I would be very grateful if someone could answer my question
Thank you for this great piece of work!
I spotted an issue in the latest version (0.4.0), that the centroid information returned by slic.slic_model.clusters
is incorrect.
Minimal working example:
import numpy as np
# Much faster than the standard class
from fast_slic.avx2 import SlicAvx2
from PIL import Image
import cv2
with Image.open('fish.jpg') as f:
image = np.array(f)
slic = SlicAvx2(num_components=512, compactness=10)
assignment = slic.iterate(image) # Cluster Map
x_centroid_map = np.zeros_like(assignment, dtype=np.uint16)
y_centroid_map = np.zeros_like(assignment, dtype=np.uint16)
for c in slic.slic_model.clusters:
y, x = c['yx']
x_centroid_map[assignment==c['number']] = x
y_centroid_map[assignment==c['number']] = y
out = Image.fromarray((x_centroid_map.astype('float')/3000*255).astype('uint8'))
out.save('x.jpg')
out = Image.fromarray((y_centroid_map.astype('float')/3000*255).astype('uint8'))
out.save('y.jpg')
I would expect the (x, y) centroid map to look like this:
X:
Y:
But it gives me this for X:
and Y is fine.
Note that this works in version 0.3.5 (which I used to generate the "expected output")!
Hope this helps 😄
It seems to be a very useful package, but does the current version support 3D images? Thanks.
Hi,
Thanks for your great work (It is really fast!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!). I really appreciate it.
I used the following codes and wanted to show the output.
import cv2
import numpy as np
from fast_slic import Slic
from PIL import Image
from skimage import io, color
with Image.open("test.jpg") as f:
image = np.array(f)
image = cv2.cvtColor(image, cv2.COLOR_RGB2LAB)
slic = Slic(num_components=35, compactness=10)
assignment = slic.iterate(image) # Cluster Map
out = color.label2rgb(assignment, image, kind='avg', bg_label=-1)
cv2.imshow("superpixels", out)
cv2.waitKey(0)
But it seems that the image cannot be shown.
Is there any solution to this?
Best,
Shuyue
Would it be possible to get a function handle that performs one single step of SLIC update?
Specifically: Given the RGB (or LAB) image, and the centroids as input, the function should output the label map. This will be very useful if the centroids are constrained to be in a certain structure.
Thank you!
I have a depth map. Can I use this code?
Is there a function to return the region information?
Hi,
Is it possible to incorporate the code in C++ project (without the python wrapper)?
Thanks
Yuval
Thank you for this package. This is awesome.
I was wondering - since I work with multispectral imagery (more than three channels) - whether it is possible to simply adapt your package for this use case?
Cheers
Your implement is real fast. While I notice that there are some difference between the result of your implement and ones of skimage.segmentation.slic
. I wonder whether it's working correctly.
Here is my code and result:
fast-slic
import numpy as np
from PIL import Image
from fast_slic import Slic
from skimage.segmentation import mark_boundaries
with Image.open("fish.jpg") as f:
image = np.array(f)
slic = Slic(num_components=200, compactness=6)
assignment = slic.iterate(image) # Cluster Map
out = mark_boundaries(image, assignment) * 255
out = Image.fromarray(out.astype('uint8'))
out.save('fish_sp.jpg')
skimage
from PIL import Image
from skimage import io
from skimage.segmentation import slic, mark_boundaries
img = io.imread("fish.jpg")
segments = slic(img, n_segments=200, compactness=6)
out = mark_boundaries(img, segments) * 255
out = Image.fromarray(out.astype('uint8'))
out.save('fish_sp_skimage.jpg')
And with config num_components=200
, compactness=6
, the result still different from one in README.md
so how can I get the same result in your demo :)
Thanks for the great work. Does it work for single channel image (1 channel instead of 3)?
See question in the subject
Hi,
I have a question regarding the performance of this model for multi-channel( > 3) images? Mainly I'm concerned about the running time.
Thanks
CAN anyone tell me how to use code to generate the image of the object segmentation?
SOS!!!
I got this error during compilation on:
Windows 10
VS2015 x64
fast-slic\src\cielab.h(292): error C2397: conversion from 'double' to 'float' requires a narrowing conversion
I resolved it by making the following change in line 288 to 292 cielab.h:
float C[9] = {
0.43395633f, 0.37621531f, 0.18984309f,
0.2126729f , 0.7151522f , 0.072175f ,
0.01775782f, 0.1094756f , 0.87283638f`
};
just adding extra f to the end of the float numbers can readily solve the problem.
Hey,
your algorithm looks very nice. Is there any chance to get all the coordinates to there corresponding superpixel? So that I have an array of points for superpixel 0, etc. My way until now is to search in the image via np.argwhere for each label. Because np.argwhere is done for every label, this is very time-consuming (multiple seconds).
Best
Hi
I installed with pip but I get this error on import:
cfast_slic.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZSt28__throw_bad_array_new_lengthv
I'm using Python 3.8
thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.