Coder Social home page Coder Social logo

bootinge / grabcutios Goto Github PK

View Code? Open in Web Editor NEW

This project forked from naver/grabcutios

0.0 1.0 0.0 27.85 MB

Image segmentation using GrabCut algorithm for iOS

License: Apache License 2.0

Objective-C 0.66% Objective-C++ 1.17% C++ 94.55% C 3.62%

grabcutios's Introduction

GrabCutIOS

Image segmentation using GrabCut algorithm in IOS

Overview

GrabCut is an image segmentation method based on graph cuts. The algorithm was designed by Carsten Rother, Vladimir Kolmogorov & Andrew Blake from Microsoft Research Cambridge, UK. in their paper, "GrabCut": interactive foreground extraction using iterated graph cuts . An algorithm was needed for foreground extraction with minimal user interaction, and the result was GrabCut.

Screenshot

screenshot.png

Requirement

  1. OpenCV Framework

Usage

  1. Import GrabCutManager
#import "GrabCutManager.h"
GrabCutManager* grabcut = [[GrabCutManager alloc] init];
  1. Set foreground boundary with a rect.
-(UIImage*) doGrabCut:(UIImage*)sourceImage foregroundBound:(CGRect) rect iterationCount:(int)iterCount;
-(void) doGrabcut{
    __weak typeof(self)weakSelf = self;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
                                             (unsigned long)NULL), ^(void) {
        UIImage* resultImage= [weakSelf.grabcut doGrabCut:weakSelf.resizedImage foregroundBound:weakSelf.grabRect iterationCount:5];
        resultImage = [weakSelf masking:weakSelf.originalImage mask:[weakSelf resizeImage:resultImage size:weakSelf.originalImage.size]];        
        dispatch_async(dispatch_get_main_queue(), ^(void) {
            [weakSelf.resultImageView setImage:resultImage];
        });
    });
}
  1. Make masking image with the adding or removing parts from result.
-(UIImage*) doGrabCutWithMask:(UIImage*)sourceImage maskImage:(UIImage*)maskImage iterationCount:(int) iterCount;
-(void) doGrabcutWithMaskImage:(UIImage*)image{
    __weak typeof(self)weakSelf = self;    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
                                             (unsigned long)NULL), ^(void) {
        UIImage* resultImage= [weakSelf.grabcut doGrabCutWithMask:weakSelf.resizedImage maskImage:[weakSelf resizeImage:image size:weakSelf.resizedImage.size] iterationCount:5];
        resultImage = [weakSelf masking:weakSelf.originalImage mask:[weakSelf resizeImage:resultImage size:weakSelf.originalImage.size]];
        dispatch_async(dispatch_get_main_queue(), ^(void) {
            [weakSelf.resultImageView setImage:resultImage];
        });
    });
}

Limitation

This program use OpenCV library. It is not use GPU in IOS. it is obviously more slower than library that it use GPU. So I want to improve this code to use GPU like GPUImage.

This algorithm is based on color value distribution. There is a limitation when foreground and background color are similar.

References

License

GrabCutIOS is licensed under the Apache License, Version 2.0. See LICENSE for full license text.

    Copyright (c) 2015 Naver Corp.
    @Author Eunchul Jeon

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

grabcutios's People

Contributors

jsharp83 avatar beanmilk avatar

Watchers

James Cloos 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.