Adjust line width

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
mij

Adjust line width

Post by mij »

I have many hundreds of Black & White molecule diagrams. I want them all to have the same line width. Particulary, I would like to resize each image so the minimun line width is 1 pixel. Is it possible to accomplish this with imageMagick?

Thank you very much.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adjust line width

Post by fmw42 »

what do you mean by line width? are you talking about the width of the image or the thickness of linear features in the image. Are the images vector or raster? Converting raster images so that linear features are 1 pixel thick is very hard. You either get broken segments or thicknesses greater than 1. Morphologic filters are probably your only hope. See my script, morphology.

Can you post a link to an example image.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Adjust line width

Post by anthony »

I think we will need more information on exactly what you are trying to do before anyone can really help you.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
mij

Re: Adjust line width

Post by mij »

I have several PNG images representing different chemical molecules. They are at different scales, for example:

Abacavir:
Image
Acetohydroxamic acid:
Image

I want the lines of both diagrams to have roughly the same thickness. I wonder if it is possible to automatize this task with imageMagick , given the -relatively- simple structure of the images, even if I know the problem is very hard.

fmw42, thank for your advise, I will test your script.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adjust line width

Post by fmw42 »

I tried a few things with my morphology script on your aceto.png image, but could not get anything appropriate for a result.
mij

Re: Adjust line width

Post by mij »

Thank you for your effort. I also tried your script with very little success.

My first thought was to somehow calculate the average thickness of the lines of the picture and scale it down consequently. Is that be possible?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Adjust line width

Post by anthony »

From what I can see you will somehow need to determine line thickness in images.

That can actually be quite hard to do, especially on a 'unknown' image.
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: Adjust line width

Post by fmw42 »

Also your characters are all not the same thickness. That makes it harder, too.
mij

Re: Adjust line width

Post by mij »

Thank you for your time.

There are some peculiarities on the images that can be used to determine line width: For instance all images have lines at 36º from the horizontal. I have studied image processing theory but have never done real programming besides some simple matlab stuff. What language/framework/... do you recommend me to use to program this ad-hoc algorithm?
Post Reply