Coder Social home page Coder Social logo

algy / fast-slic Goto Github PK

View Code? Open in Web Editor NEW
258.0 6.0 34.0 2.13 MB

20x Real-time superpixel SLIC Implementation with CPU

License: MIT License

C++ 72.38% C 1.85% Python 25.43% CMake 0.34%
superpixel-algorithms superpixels python slic image-segmentation blazingly-fast

fast-slic's People

Contributors

algy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fast-slic's Issues

PEP 517 support

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.

Zero parameter mode

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).

add support for masks

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

The meaning of Clusters?

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

Incorrect centroid location

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:
x
Y:
y

But it gives me this for X:
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 😄

How to show the segmented image?

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

Function for single step of SLIC

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!

Return regions

Is there a function to return the region information?

Using Fast-Slic in C++

Hi,

Is it possible to incorporate the code in C++ project (without the python wrapper)?

Thanks
Yuval

Configurable for multispectral images?

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

difference in result

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:

  • slic of 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')

fish_sp

  • slic of 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')

fish_sp_skimage

And with config num_components=200, compactness=6, the result still different from one in README.md

result in README.md.

here is my input fish.jpg
fish

so how can I get the same result in your demo :)

Performance on multi-channel images

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

SOS

CAN anyone tell me how to use code to generate the image of the object segmentation?
SOS!!!

compile error

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.

Any Description?

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.