3
$\begingroup$
img=Import["https://i.stack.imgur.com/NjyIK.jpg"]

dress

The dress is closely similar with the color of the background stair rail.

How can I binarize the image to get the dress mask or human mask?

Any methods of Binarize is acceptable, like RegionBinarize, training an semantic segment model

I've tried several Binarize* functions, and EdgeDetect functions, and confirmed that there are some challenges in the right-down part of the dress.

Background explaination: Why to segment? For example, consider there are many dress model pictures, we can cluster them by dress, and remove background we could get better features, for example textures and shapes.


upadte:

Maybe someone knows more about traditional segment methods and has various experiences. Thanks for @rhermans 's comment.

RemoveBackground[Import["https://i.stack.imgur.com/NjyIK.jpg‌​"], {"Foreground", {RGBColor[ 0.9157048167754652, 0.8904987221508752, 0.8709273742640429], 0.062}}]

ImagePartition is a good idea with better region effect in Watershed.

WatershedComponents[,mask]//Colorize

enter image description here

$\endgroup$
14
  • 1
    $\begingroup$ Do you want the left forearm and hand in front of the dress removed as well? $\endgroup$
    – m_goldberg
    Jul 13, 2017 at 7:38
  • 2
    $\begingroup$ Also, are you concerned only with this particular image or are you looking for general method that would on other images with a similar problem? $\endgroup$
    – m_goldberg
    Jul 13, 2017 at 7:41
  • 3
    $\begingroup$ I think one way would be to define a Mask manually (related How to retouch (smart fill) photo image?). Or you can try splitting your image into segments for better contrast img = Import["https://i.stack.imgur.com/NjyIK.jpg"];Grid[Partition[EdgeDetect[#] & /@ (ImagePartition[img, 50]~Flatten~1), 4], Spacings -> {0, 0}] $\endgroup$
    – Sumit
    Jul 13, 2017 at 9:05
  • 1
    $\begingroup$ Do you need a fully automated procedure or can you afford doing steps by hand? I think you should edit your question and explain better what you need. As it stands, the question is too broad. $\endgroup$
    – rhermans
    Jul 13, 2017 at 10:25
  • 6
    $\begingroup$ Why do you want to remove the dress? $\endgroup$
    – bill s
    Jul 13, 2017 at 13:43

2 Answers 2

4
$\begingroup$

My take at this—not perfect by any means.

The main feature I would exploit is that the area you want to segment is spatially well defined, so you can combine the color information with the position one.

Let's first define a white mask:

white = Binarize[ColorDistance[i, Darker[White, .1]], {0, .1}]

white_mask

and a white stripe inside the image boundary:

border = ImagePad[ImagePad[0 i, -60], 60, 1];

We can now combine them in a backgroundMask and a foregroundMask

backgroundMask = Erosion[border + ColorNegate[white], 3];
foregroundMask = Erosion[ColorNegate[border], BoxMatrix[{60, 30}]] * white;

{backgroundMask, foregroundMask}

component_mask

and use them in GrowCutComponents to assign the remaining pixels.

mask = Image[
   GrowCutComponents[i, {backgroundMask, foregroundMask}] - 1
];

The result is not perfect—no spoilers here—but almost all the extra white has been removed

SetAlphaChannel[i, Blur[Erosion[mask, 2], 1]]

dress_alpha

You can tweak the code to make the boxes a little more asymmetric and improve the segmentation area, but—as others have said—there's a limit to where automatic (non semantic) segmentation can take you.

$\endgroup$
3
  • $\begingroup$ MaxDetect[img, .2] will give your white $\endgroup$
    – yode
    Jul 13, 2017 at 19:09
  • $\begingroup$ @yode only for pure white though—GrayLevel[1]. $\endgroup$
    – Batracos
    Jul 13, 2017 at 19:12
  • $\begingroup$ see my answer, the Neural Network is very useful $\endgroup$ Aug 9, 2018 at 10:49
4
$\begingroup$

Cool result of NetModel of 11.3.

You can download the models like Ademxapp Model A1 Trained on PASCAL VOC2012 and MS-COCO Data from Wolfram Netmodel Reposity

Open the Notebook, then import the sample image, and run the code.

img=Import["https://i.stack.imgur.com/NjyIK.jpg"]
result[img]

enter image description here

enter image description here

$\endgroup$
7
  • $\begingroup$ @C.E. I've added an link, you can download the example notebook there $\endgroup$ Aug 9, 2018 at 10:12
  • $\begingroup$ @C.E. OK, I think in this example, it's needless to copy codes from official help examples into answer. $\endgroup$ Aug 9, 2018 at 10:47
  • $\begingroup$ @C.E. Comment cann't show image. This method solved my question greatly, I think its useful for many other people. $\endgroup$ Aug 9, 2018 at 11:04
  • $\begingroup$ @C.E. The most useful point is one know there are some NN models in Mathematica 11.3 to do such an thing. $\endgroup$ Aug 9, 2018 at 11:06
  • 1
    $\begingroup$ Using an image segmentation network is a pretty good idea; I don't see what the problem is with this answer. However, it would be better to just give the complete code that downloads the network from within a notebook. I.e., resource = "Ademxapp Model A1 Trained on PASCAL VOC2012 and MS-COCO Data"; ResourceObject[resource]; net = NetModel[resource]; net[img]. Furthermore, it seems like this network doesn't get you all the way to the final answer, though it's definitely useful as a first step in defining a mask for further segmentation analysis. $\endgroup$ Aug 14, 2018 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.