Quickest way to get an output image to show "structure" of the image

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
troynguyen8
Posts: 7
Joined: 2018-10-14T18:51:53-07:00
Authentication code: 1152

Quickest way to get an output image to show "structure" of the image

Post by troynguyen8 » 2019-01-08T12:42:35-07:00

Magick version:
Version: ImageMagick 7.0.8-11 Q16 x64 2018-08-29 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib cairo flif freetype gslib heic jng jp2 jpeg lcms lqr lzma openexr pangocairo png ps raw rsvg tiff webp xml zlib

OS: Windows 10

Hey all, I'm trying to use ImageMagick to get the structure of pdf statements. Here is the input/output of what I'm talking about:

Input:
Image

Output:
Image

Right now, I am accomplishing this by first applying a blur to the image, and then after that making any non-white pixels black.

magick convert "input.png" -blur 0x08 "blur.png" &&
magick convert "blur.png" -fill -black +opaque white output.png

The only issue with this is that the blur command is very computational intensive, and takes much longer than I'd like it to. One consideration I had is keeping using the MPR format (memory persistent register) since the write of the blur image to disk is unneeded to me. However, I'd like to know if there's a faster way to do the operation I want without using blur at all. It may be worth noting that I'd like to parallelize multiple calls to this command in the future.

Thanks in advance!

snibgo
Posts: 11335
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Quickest way to get an output image to show "structure" of the image

Post by snibgo » 2019-01-08T13:43:31-07:00

Why use two converts instead of just one?

For v7, I suggest you use "magick", not "magick convert".

I don't know what you mean by "the structure of pdf statements". But you will get a similar effect by rasterizing the PDF at a small density, with no blur at all. Something like:

Code: Select all

magick -density 10 input.pdf output.png
Change the density number to suit.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 24612
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Quickest way to get an output image to show "structure" of the image

Post by fmw42 » 2019-01-08T13:45:55-07:00

First, in IM 7, use magick, not magick convert and not convert. Otherwise you are actually using IM 6. You can write both statements in one command line as

Code: Select all

magick "input.png" -blur 0x08 -fill black +opaque white output.png
Your command does not make sense to me. There is no such color as -black. Is that a typo? Second -blur 0x08? Why 08? Should it not just be -blur 0x8?

One other option would be to use morphology, though I am not sure which is faster. But there may be something wrong with your file, since I get an error message:

Code: Select all

magick "input.png" -blur 0x08 -fill black +opaque white output.png
magick: sBIT: invalid `input.png' @ warning/png.c/MagickPNGWarningHandler/1747

Code: Select all

magick image.png -threshold 0 -morphology erode disk:20 tmp.png
magick: sBIT: invalid `image.png' @ warning/png.c/MagickPNGWarningHandler/1747.
Lastly, there is no PDF. The image you posted is PNG.

troynguyen8
Posts: 7
Joined: 2018-10-14T18:51:53-07:00
Authentication code: 1152

Re: Quickest way to get an output image to show "structure" of the image

Post by troynguyen8 » 2019-01-08T14:05:47-07:00

Hey all, thank you for your responses. I have good direction from here! I hadn't realized that in IM 7 you can just specify `magick`, that's good to know! I had a couple of typos such as the 0x08 and -black, I apologize for that. To clarify, I had already converted my pdf to a png and that's what I showed here. I'll let you all know if I run into any other issues

Post Reply