Page 1 of 1

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

Posted: 2019-01-08T12:42:35-07:00
by troynguyen8
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!

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

Posted: 2019-01-08T13:43:31-07:00
by snibgo
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.

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

Posted: 2019-01-08T13:45:55-07:00
by fmw42
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.

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

Posted: 2019-01-08T14:05:47-07:00
by troynguyen8
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