1

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.

5
  • Can you explain what is the feature that makes a difference between a high contrast edge which earns a stroke and a high contrast edge which does not earn a stroke. You wrote you can see it and draw a selection for it. What the program should see?
    – user82991
    Mar 26, 2020 at 21:39
  • I've provided some clarification, although I didn't do a great job of doing it by hand, I'll admit. Mar 27, 2020 at 0:05
  • Seemingly you know nothing of how well photographing should be prepared and performed for high quality easy background removal. Your image is noisy, unsharp and at the edge there's virtually no contrast in many places. The only way for acceptable background removal from this shot is to use human reasoning i.e. to draw a path and use it as a selection. No software (except artificial world aware intelligence) can guess where the wanted edge is. Sorry. Just for a reference see the result of drawing a path around the hand dropbox.com/s/0ldzvnmcl8tffkk/OneHand.png?dl=0
    – user82991
    Mar 27, 2020 at 0:47
  • :) No, I literally grabbed a random image off of my harddrive. So, if I were to pick a situation with higher contrast (say, doing it against a light wall without the shadow), is there a chance of doing the same thing? Or am I actually asking for a hard thing in image processing? Mar 27, 2020 at 0:49
  • Take the photo against a background light = Good if the light is in balance with other light. Another silhouette only photo without moving the target nor camera would give a good contrast based selection. Pro equipment is a must. Noisy unsharp mess like your example is useless for pro quality works
    – user82991
    Mar 27, 2020 at 10:47

2 Answers 2

2

The example photo is noisy and unsharp, there's no contrast at all in many places of the edge. Unsharpness and shadow over the edge needs something which knows what is the hand and what is not. As already said in a comment, in automatic software that means artificial intelligence and world awareness. I have not seen such software for photo editors, but that doesn't prove it's non-existent.

The common way to remove the background properly in cases like this is to draw a path around the object and use it as a selection. The next image shows what's the result with that method:

enter image description here

Drawing the path took less than 120 seconds and I'm not by any means the master of Bezier curve drawing.

The result is not perfect against white background because dark edges look dirty. Darker new background wouldn't have that contradiction. An experienced image editor would slice off the dirty area at least at the lowest fingertip if he knew it's safe without changing the essential content and the background will be light.

You expected a way for coarse marking (=painting) where the outline goes and automatic generation of the exact selection or layer mask. The idea is old, commercial background removal tools with this principle have been for sale a long time. Topaz Labs and ON1 at least sell them. GIMP has one, too. It's the Foreground Selection tool. With it you draw a curve surely outside the object, paint some amount over the interior and let the tool to find where the edge is between your drawings. The tool has much parameters to be set.

Those guided edge finding and selection or mask making tools work extremely well when the edge is clean, but your example needs in many places very accurate guidance due the unsharpness and missing contrast. Without it you'll get very fuzzy result. All in all if the image is poor it's the same as drawing a clipping path, only much slower because time was wasted in good hopes.

If one expects easy background removal which is based on color or contrast the photographing session should be planned and performed to serve this goal. We can see ads of magical one click background removal tools which in demos seem really to work. But in every case the photographing was prepared for perfect contrast or color border. For example a woman poses on a beach and the blue sky is her background. One click and even the waving hair is perfectly separated. To get the same indoors you must have a pro quality camera, tripod, lights and background. And a huge amount of studying and practicing.

1

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

1
  • That works most admirably! Thank you. Mar 29, 2020 at 17:01

Your Answer

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

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