Draw an outline based on contrast?

Semi-related to How to automatically draw the edge between two regions in GIMP?, is there any way in GIMP to stroke an area and create a line along areas of high contrast? I know that there are edge-finding filters, but they generally operate over an entire layer or selection thereof. I could probably draw a path and expand it into a selection over the area, then run the edge-finding, but it feels like this is something that can be done in a more automatic fashion.

The intent is basically to simplify tracing an object either to generate a line outline, or to trace the actual selection area for the purpose of isolating it from the background, similar to Contrast-based image outlining feature?, but not over the entire image.

To give an example, let’s say I have this image of my hand over a reasonable neutral background:

Image of my hand against a wall

If I run edge detect on it, I might get the following:

Image of my hand with Edge Detect

That provides Edge Detect over the entire image (and yes, I know I could probably do a better job of adjusting the contrast so that it gets the edge of my hand instead of that and all of my skin crenelations)

If I use Quick Mask, I can paint a selection area around the outline of my hand without being precise, run edge detect over that selection, and then delete the other parts.

Painted selection of outline, followed by edge detect

Now obviously, I’m not good at adjusting the edge detection, although I’ve had some luck with using Threshold to get the edge back, and in this particular image, the shadow makes part of the hand not have a high contrast against the background, but I feel like there are a lot of cases where it would make sense to be able to just kind of paint the outline of something, and get the actual outline, probably with some adjustment of parameters so that you get that stark outline and minor differences around it.

Answer

The image you are trying to use is not very good for automating this. The shadow is problematic. Try instead to take a picture of the subject against a plain background, but far enough away from the background itself so as not to cast a shadow.

Assuming you have a suitable image, there is a semi-automatic way using the Foreground Select tool in GIMP. The example below was made using GIMP 2.10.18.

  1. Choose the Foreground Select tool, and in the tool options choose the “Matting Levin” option. I find this option gives the best results.

  2. Make a rough outline with the lasso around the object to be extracted, then hit Enter

enter image description here

  1. Roughly paint around the inside of the subject to be extracted, trying not to go over the edge of the subject. The gap between the two selections will be used by GIMP to determine the edge of the object based on the contrast between the background and subject in the photo

enter image description here

  1. When you have finished, select “Preview mask”, then if it’s OK, hit Select. This will create a selection.

  2. Apply a layer mask, and choose the “From selection” option.

The result is pretty good, and it makes quite a nice mask without too much effort. Here’s the result showing the image, and the mask it generated.

enter image description here

Attribution
Source : Link , Question Author : Sean Duggan , Answer Author : Billy Kerr

Leave a Comment