Problems removing noise around text [SOLVED]

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
thofas
Posts: 8
Joined: 2014-08-14T01:50:08-07:00
Authentication code: 6789

Problems removing noise around text [SOLVED]

Post by thofas »

Hello everyone,

I have problems reducing the noise (sparkles) around text i have placed into an image with "convert caption".
I tried a lot of statements/commands without any success.

The convert command is called with the following parmeters:

-quality 100
-pointsize 14
-size 300x200
-font /pathTo/arial.ttf
caption:"demo text"

This command is called for several images which will be merged into one single image via the composite command in the next step.

On this image (https://www.dropbox.com/s/116uqvbvlqzbb ... magick.jpg) you can see the little white sparkles I want to remove.
Can someone give the correct statement for this intention?

Or ist possible that there is any mistake generating the text so that the sparkles are not even displayed?

Thanks for your help!
Last edited by thofas on 2014-08-15T06:11:22-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problems removing noise around text

Post by snibgo »

Don't save it as jpeg. Jpeg is horrible for areas of flat colour -- it mangles the colours.
snibgo's IM pages: im.snibgo.com
thofas
Posts: 8
Joined: 2014-08-14T01:50:08-07:00
Authentication code: 6789

Re: Problems removing noise around text

Post by thofas »

this is not the generated image it's only cropped from a screenshot...the generated image is a png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problems removing noise around text

Post by fmw42 »

What version of IM and what platform? Post your full exact command line. We cannot see what colors are specified and don't know what else might be involved. We need to be able to exactly reproduce your command line to see if we get the same issue.

Was this speckling in the original png file before loaded in your viewer and screen captured? Perphap the display or screen capture converted to jpg and caused the speckling?
thofas
Posts: 8
Joined: 2014-08-14T01:50:08-07:00
Authentication code: 6789

Re: Problems removing noise around text

Post by thofas »

We run on a Linux based system with IM version 6.5.3.

Following the full command line:

/usr/local/im/bin/convert -quality 100 -pointsize 14 -size 400x200 -font /font/arial.ttf caption:"this is a demo text" test.png

The specklings are first shown after this step.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problems removing noise around text

Post by fmw42 »

Your version of IM is over 350 versions old. I would suspect it has a bug. You should upgrade IM.

It could also be an older version of PNG that is at issue.

Also your command has no color specified, so it cannot be what you used to create the image you showed earlier. Furthermore, the image would not correspond to the size you specified in your earlier command. You would have had to crop it. Also -quality 100 is not necessarily a correct quality for PNG (but would have been for saving as jpg). So did you really save the file as PNG or JPG?

So again, please provide the exact code that was used to create the image you provided.


Try this command. It works fine for me with no speckling. What does it look like for you?

Code: Select all

convert -size 400x200 -background lightblue -fill black -pointsize 14 -font arial \
-gravity center caption:"this is a demo text" -gravity center -crop 128x26+0+0 +repage test.png
thofas
Posts: 8
Joined: 2014-08-14T01:50:08-07:00
Authentication code: 6789

Re: Problems removing noise around text

Post by thofas »

The image I've posted earlier is a crop from a screenshot of the complete generated image.
I generate different single images with texts inside and composite them later to one image, from this image (the backround color is in another image) I took the screenshot.
...but the spacklings are visible before the composite command is called.

But what I want to do ist to generate the texts on transparent PNGs, maybe this was not clear in my last posts, sorry for that.

I also missed to say that I call this command after the last to remove the white background:

Code: Select all

/usr/local/im/bin/convert test.png  -transparent white test.png
An Update to another IM version won't pe possible because of hoster restrictions.

The command you've posted works fine on my system, too. So the problem muste be somewhere else...

EDIT:

Here is the background image where the different PNGs within the texts will beplaced on:

https://www.dropbox.com/s/52d192oigf7pr ... ground.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problems removing noise around text

Post by snibgo »

The trick is to show us the exact commands that make the speckling. If the commands need input images files, then also show those.
snibgo's IM pages: im.snibgo.com
thofas
Posts: 8
Joined: 2014-08-14T01:50:08-07:00
Authentication code: 6789

Re: Problems removing noise around text

Post by thofas »

Here are all commands that are called:

First command (generate PNG with text, for every single text)

Code: Select all

/usr/local/im/bin/convert -quality 100 -pointsize 14 -size 400x200 -font /font/arial.ttf caption:"this is a demo text" test.png
Second command (remove white background from PNG, for every single text)

Code: Select all

/usr/local/im/bin/convert test.png  -transparent white test.png
Third command (compose them together with background image)

Code: Select all

/usr/local/im/bin/convert background_image.png \
	text_image_1.png -geometry +165+10 -composite \
	text_image_2.png -geometry +165+40 -composite \
	text_image_3.png -geometry +635+60 -composite \
composed_image_with_texts.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problems removing noise around text

Post by snibgo »

You haven't provided a complete set of commands that someone else can run.

Assuming the background image is the one you supplied above, I ran this...

Code: Select all

convert -quality 100 -pointsize 14 -size 400x200 caption:"this is a demo text" test.png

convert test.png  -transparent white test.png

convert background.png test.png -geometry +165+10 -composite composed_image_with_texts.png
... on IM v6.8.9-5 on Windows 8.1. There is no speckling. Here is the output:
Image
If your result to these commands has speckles, please post it.
snibgo's IM pages: im.snibgo.com
thofas
Posts: 8
Joined: 2014-08-14T01:50:08-07:00
Authentication code: 6789

Re: Problems removing noise around text

Post by thofas »

I've set the text a littler lower into the blue section, so the result becomes clearer.

There are speckles again as you can see in my output:

https://www.dropbox.com/s/jjo1p9ruip51o ... _texts.png

Could it be that there are any problems with the fonts? It looks like your default font ist Arial?
In my case IM uses a Times New Roman as default. But when I set the -font paramter to use the Verdana font the output looks similar.

Output with Verdana font:

https://www.dropbox.com/s/cbyn82zgj8nwh ... erdana.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problems removing noise around text

Post by snibgo »

Ahh, now I understand.

When text etc is written, the edges are antialiased. So pixels at the edge are light gray, dark gray and so on. You make white transparent, but leave the gray pixels at the edge.

When you create the text, use "+antialias" to turn it off. Better, use "-background none" to make the background transparent. Then you don't need to turn white into transparent.
snibgo's IM pages: im.snibgo.com
thofas
Posts: 8
Joined: 2014-08-14T01:50:08-07:00
Authentication code: 6789

Re: Problems removing noise around text

Post by thofas »

yeah, nice to see that we come closer to the problem! ;-)

but we're still not quite there...

1. when I use "+antialias" the text will be reduced very hard, as you can see in the picture below.
2. the command

Code: Select all

convert test.png  -background none test.png
doesn't turn my background into transparent... :-/

https://www.dropbox.com/s/vwgyr4np7hnjclt/test.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problems removing noise around text

Post by snibgo »

Use "-background none" when writing the caption:

Code: Select all

convert -background None -quality 100 -pointsize 14 -size 400x200 caption:"this is a demo text" test.png

convert background.png test.png -geometry +165+50 -composite composed_image_with_texts.png
snibgo's IM pages: im.snibgo.com
thofas
Posts: 8
Joined: 2014-08-14T01:50:08-07:00
Authentication code: 6789

Re: Problems removing noise around text

Post by thofas »

Yeah, that's it!!! Thank you!
That's crazy I used the "-background" parameter in the past but apparently in the wrong place... :)
Post Reply