Coder Social home page Coder Social logo

2018_fall_image_processing_final_api_segmenter's Introduction

Segmenter

This module separates background and foreground, using labeled key points.

Prepare source code

git clone https://github.com/cy20lin/2018_fall_image_processing_final_api_segmenter ~/segmenter
cd ~/segmenter
git submodule update --init --recursive

Build this module

cd ~/segmenter
mkdir build
cd build
cmake ..
make

Test this project

cd ~/segmenter
cd build
./test_api_segmenter_segmenter_cimg

Ideas

Given a image and with labeled keypoints (label as foreground and background). We want to calculate the label for each pixel in the image.

Given that we already know the label of some point (pixel), we are going to utilize those point to generate the label information for other not-yet-labeled pixel.

It take three steps to generate labels for all pixels: Blur, Calculate Priority Map, and watershed.

First, blur the image for a smoother image. Avoiding high frequency noises.

Second, calculate the priority for each pixel in this image. Use the reciprocal of gradient as the priority value. The pixel with high priority is in the place where the variation of intensity is low. The pixel with low priority on the other hand is in the place where the variation of intensity are high.

Third, using watershed to calculate the labels. By propagating from the neighbors of know labels, those pixel with high priority has higher chance to be labeled first. Stop, propagating as whole pixels in image has already been labeled.

The algorithm under the hood

Step1. Blur the image

Use Guassian filtering, with sigma = max(image.width, image.height) * 0.002;

./doc/blurred.png

Step2. Build the Priority Image

Get the gradient vector (x y directions) for each channel (r, g, b),

Get the length (norm) of each gradient vector for each channel.

Sum length for gradient vector in each channel.

Add 1 to the sum and divide 1 using this sum.

Now we got a priority at this point whose value is in the range (0,1].

For smooth areas the priority value is high, otherwise the priority is low.

Gradient in x direction.

./doc/gx.png

Gradient in y direction.

./doc/gy.png

Priority Image, with black = 0, white = 1

./doc/p.png

Step3. Watershed

Given the labeled keypoints (i.e. foreground or background) and priority image.

Initialization:

For each neighbor (we use 8-neighbor in this project) of the keypoints.

Push each neighbor point into priority queque given their priority.

Propagation:

Pop the point with the highest priority.

Point with higher priority would be processed first.

Push all non-labeled neighbors around this point into priority queue.

Set the label of this point to the label of the labeled neighbor.

Stop when priority queue is empty.

Following figure is the result mask, with background in color red, foreground in color green.

./doc/kmask.png

References

2018_fall_image_processing_final_api_segmenter's People

Contributors

cy20lin avatar jimmy-hu avatar

Watchers

 avatar  avatar

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.