guozhonghao1994 / Foreground_Background_Segmentation

Final Project of Advanced Data Structure and Algorithm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Image-Foreground-Background-Segmentation

Introduction

Our target is to design and implement an algorithm to segment any input images into foreground and background. For basic task, we have used cluster classification, combining with Network Flow to achieve this goal. All the input images are down-sampled and compressed firstly to make the processing more efficient. For the second step, we have implement cluster method GMM, K-means and our extension part to get improved cluster result. After that, Network Flow has be accomplished to label and divide pixels into two groups, which represents background and foreground.

For extension part, we have designed an application to remove certain part of image interactively, and have made attempts and exploration on a more efficient method. The new method could generate two likelihood score from more than two clusters. It is developed by ourselves and could take advantage of a more stable performance than the other two.

C++ Version Installation Guide (Windows)(UI)

  1. Install QT 4.6

    https://www.qt.io/download

  2. Install Python 3

    https://www.python.org/downloads/

  3. Install matplotlib, pylab, numpy, sklearn, cv2scipy, PIL , copy for Python

  4. Unzip all project files and open the *.pro file in QT platform

  5. Unfold the folder on the left bar and double click the *.pro file, entering edit mode

  6. Add these two lines to the file (different PC varies):

    INCLUDEPATH +=C:/Python36/include/

    LIBS += C:/Python36/libs/python36.lib

  7. Open pyconfig.h and modify as follows

    #ifdef _DEBUG

    //# define Py_DEBUG

    #endif

  8. Open object.h and modify as follows

    #if defined(Py_DEBUG) && !defined(Py_TRACE_REFS)

    // #define Py_TRACE_REFS

    #endif

  9. Make sure the compiler runs in MSVC 2017 64 bits and debug mode, start!

Unluckily, you need to delete the output files generated during the process.

C++ version without UI:

If you want to run the CPP version without UI, you could enter the CPP file and run three files in order: GMM.py, push_relabel.cpp, show.py.

Each program will read the output file generated from the last file automaticaly. What you need to do is to enter the GMM.py file and change the address of the inputfile and perform the same change in the show.py. Also, you need to change the path in push_relabel.cpp file but don't change the file name!. This cpp file will take about 10 seconds to 60 seconds to run your picture based on the size of your picture.

The show.py will show the background and foreground of the picture and save them in the local file.

Python Version Installation Guide(with UI)

  1. Download the file from our GitHub

  2. Install matplotlib, pylab, numpy, sklearn, cv2scipy, PIL , copy for Python(Using pip install 'libraray name' in the command line)

  3. Drag any picutes you need to the file

  4. Using "Python UI_python.py" command in the command line to run the UI

  5. Upload the image form your computer, click any point you care about in the picture, and click "Sever Image" button to run the program. It will takes about 2-8 minutes to finish the process(It depends on the size of your input picture)

  6. You could see the forground or background picture in the window and both pictures will be saved in the file called "one.bmp" and "two.bmp".

About

Final Project of Advanced Data Structure and Algorithm

License:Apache License 2.0


Languages

Language:C 64.9%Language:C++ 32.8%Language:Python 2.0%Language:DTrace 0.1%Language:QMake 0.1%