iSankha007
iSankha007

Reputation: 395

Cropping image By selecting Object and color matching

We are developing an app where we need to crop an image according to the selecting object area. User will draw a line and we need to select the object and crop it .This crop need to be like the app: YourMoji

So far we have tried to get the color of the pixels along the line and then comparing those with the color of every pixel in the image and making a path from it to clip the image. But the almost going no where.

Croping image

Is it possible through this way to crop an image or we are going in the wrong way? Can anyone provide a way to do this Or suggest a way to modify the way we have worked so far?
Any advice and suggestions will be greatly appreciated!
Thanks in advance.

Upvotes: 1

Views: 188

Answers (2)

Lighten
Lighten

Reputation: 46

I guess what you want is the image segmentation algorithm called Graph Cut.

Here are two Github repositories, hope these would help:

Upvotes: 1

James Webster
James Webster

Reputation: 32066

I'm not exactly clued up on image manipulation, but the first algorithm that comes to mind is something like this:

  • Take the average of the pixels in the line (as you have)
    • Since you appear to want faces, you might want to weight reds and blues over green. Not much green in faces of any skin tone.
  • For each pixel, if the colour is within a given threshold outside of your selected average, remove it / make transparent.

  • Perhaps the closer to the original line (or centroid), the less strict the threshold becomes.

I'd then provide the user with some tools for:

  • Sensitivity: how large the threshold is
  • Eraser: to remove parts of the image that your algorithm missed
  • Paintbrush: to replace parts of the image that your algorithm incorrectly removed.

Upvotes: 1

Related Questions