Possible to retrieve the full outline of an image?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
HikaruYami

Possible to retrieve the full outline of an image?

Post by HikaruYami »

Photoshop has a free downloadable plugin for this, but I need to have a program do this automatically followed by several more steps, the others of which I at least have a vague idea of how to do.

Image

Image

It should look something like that (what is generated in the example use of the aforementioned plugin; no, I do not need it to look that "pretty", and their tool usually doesn't do such a thing either, but I need it to catch notable depth and color changes all within the image, not merely the outer edges of a large body (though if it's a large, uniform object like a sphere, of course that's what it would do, lol).
HikaruYami

Re: Possible to retrieve the full outline of an image?

Post by HikaruYami »

Oh god, thank you SO much, I must not have looked even a quarter as hard as I thought >.<

Really, thank you very much!!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Possible to retrieve the full outline of an image?

Post by anthony »

The above looks like it could use the new Convolving edge Detection kernel stuff.
http://www.imagemagick.org/Usage/convolve/#edgedet

Fred is however the better person to ask about it though -- fwm42?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Possible to retrieve the full outline of an image?

Post by fmw42 »

Looks to me like a Canny type edge detection. But you can get close with a laplacian, for example

convert out_swap02.jpg \
-set option:convolve:scale '-1!' \
-morphology Convolve Laplacian:0 \
-colorspace gray -auto-level -threshold 5% -negate \
out_swap02_laplacian.jpg
HikaruYami

Re: Possible to retrieve the full outline of an image?

Post by HikaruYami »

Thanks for all the help~

But while I'm very interested in that last one, it seems to be giving me tons of junk pixels everywhere (medium-sized pseudo boxes all over the picture). Why is that?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Possible to retrieve the full outline of an image?

Post by fmw42 »

HikaruYami wrote:Thanks for all the help~

But while I'm very interested in that last one, it seems to be giving me tons of junk pixels everywhere (medium-sized pseudo boxes all over the picture). Why is that?
What version of IM do you have? It may be older than the new -morphology function. If that is the case, you can still use -convolve "-1,-1,-1,-1,8,-1,-1,-1,-1". I am on IM 6.6.2-7 Q16 Mac OSX Tiger. When I run this, I get the following:

convert out_swap02.jpg \
-set option:convolve:scale '-1!' \
-morphology Convolve Laplacian:0 \
-colorspace gray -auto-level -threshold 5% -negate \
out_swap02_laplacian.jpg

Image

Be sure not to forget the % in the threshold.

If you are on windows. see about doubling %% at http://www.imagemagick.org/Usage/windows/
HikaruYami

Re: Possible to retrieve the full outline of an image?

Post by HikaruYami »

Oh, yeah, I didn't consider that it might require something different on windows. But I do have the most recent imagemagick version~

Is it also possibly relevant that I'm working with a drastically larger image?

Thanks again for all your help!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Possible to retrieve the full outline of an image?

Post by fmw42 »

HikaruYami wrote:
Is it also possibly relevant that I'm working with a drastically larger image?

p!
Definitely!

try a larger threshold. But...

You might need a larger laplacian filter to avoid lots of small noise.

You might try either the LoG or Gradient Magnitude filters. See
http://www.imagemagick.org/Usage/convolve/#log

or last examples at
http://www.imagemagick.org/Usage/convolve/#sobel
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Possible to retrieve the full outline of an image?

Post by anthony »

The fact that you are using a larger image could explain why your original sample look like it contains a lot of grey pixels. That is something you don't get which threshold is applied.

If you do have the latest IM you should also have the 'LOG' morphology kernals which generates a larger edge detection kernel that can 'delete' extraneous edges better. Sobel and other edge detector kernels could also be useful too. But you will then also have to use the -morphology convolve operator as the older operators have yet to be converted to the new method.

See http://www.imagemagick.org/Usage/convolve/ for more info. Fred can give more practical examples (yet to be added to IM examples).

I still have a speed issue (twice as slow) to resolve first and the older versions ability to use a GPU has to also merge into the morphology version. Once that is done then things can continue.

Note that a 'Canny' Edge detection was mentioned. This generates continuous lines in the image, but at the cost of disconnecting 'T' junctions. Unfortunately it has yet to be implemented, and may not be added for a long time yet, unless we get an interested programmer. It's so far down my own 'ToDo' list that it does not even appear, though I am interested in the operator.


Looks like Fred (fwm42) beat me to the submit with a similar answer and appropriate links to the exact same kernels I mentioned. :D
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
HikaruYami

Re: Possible to retrieve the full outline of an image?

Post by HikaruYami »

Thanks very much! Both of your replies helped a lot!
Post Reply