3
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

HyperGroups
  • 8,619
  • 1
  • 26
  • 63

2 Answers2

4

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.

Batracos
  • 2,105
  • 14
  • 14
4

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

HyperGroups
  • 8,619
  • 1
  • 26
  • 63
  • @C.E. I've added an link, you can download the example notebook there – HyperGroups Aug 09 '18 at 10:12
  • @C.E. OK, I think in this example, it's needless to copy codes from official help examples into answer. – HyperGroups Aug 09 '18 at 10:47
  • @C.E. Comment cann't show image. This method solved my question greatly, I think its useful for many other people. – HyperGroups Aug 09 '18 at 11:04
  • @C.E. The most useful point is one know there are some NN models in Mathematica 11.3 to do such an thing. – HyperGroups Aug 09 '18 at 11:06
  • @C.E. How about now? is it like a answer? – HyperGroups Aug 14 '18 at 11:00
  • 1
    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. – Sjoerd Smit Aug 14 '18 at 13:07
  • I deleted my comments because there is no reason for them to forever mar this answer. I still believe that this answer could be better though, Sjoerd said it pretty well. – C. E. Aug 14 '18 at 17:13