Filter to improve some tif images

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?".
Jean-Pierre Coulon
Posts: 41
Joined: 2016-10-04T02:08:22-07:00
Authentication code: 1151
Location: Nice, France

Filter to improve some tif images

Post by Jean-Pierre Coulon » 2018-06-22T07:38:38-07:00

I have a tif image with many horizontal and vertical lines. When I zoom a horizontal line I often see irregular borders between the black and white areas. Translating this in .pbm this gives several full of zeroes, a line like 000001010010110011111 and several lines full of ones.

If I could transform the complicated line into 00000000001111111111 this would not affect the resolution of useful details but this would significally reduce the size ot the tif. Same request for a vertical line.

Of course a Gaussian-blur with sigma = 3 or 4 will do the job but it will blur useful details at other areas. Is there the right filter for me?

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

Re: Filter to improve some tif images

Post by snibgo » 2018-06-22T08:15:50-07:00

A sample image would help us understand the problem.
snibgo's IM pages: im.snibgo.com

Jean-Pierre Coulon
Posts: 41
Joined: 2016-10-04T02:08:22-07:00
Authentication code: 1151
Location: Nice, France

Re: Filter to improve some tif images

Post by Jean-Pierre Coulon » 2018-06-22T08:19:01-07:00

How can I attach a sample that is not on the web?

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

Re: Filter to improve some tif images

Post by fmw42 » 2018-06-22T09:01:14-07:00

This forum does not allow uploads. So you need to post the image to some free image hosting service and then put the URL here. If your image is proprietary, can you create or find one that is not, which shows the same issue?

Also please always provide your ImageMagick version and platform? Perhaps you are using an old version and it needs upgrading or your delegate for the input or output format needs updating.

Jean-Pierre Coulon
Posts: 41
Joined: 2016-10-04T02:08:22-07:00
Authentication code: 1151
Location: Nice, France

Re: Filter to improve some tif images

Post by Jean-Pierre Coulon » 2018-06-22T19:44:14-07:00

I hope an inline pbm does'nt spam this forum :)
P1
50 15
0 0 0 0 0 0 0 0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 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 1
0 0 1 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

How can I cause Imagemagick to provide its version? It is not that I am obtaining an error message I don't understand.

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

Re: Filter to improve some tif images

Post by fmw42 » 2018-06-22T22:31:50-07:00

Code: Select all

convert -version
will give you the ImageMagick version.

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

Re: Filter to improve some tif images

Post by snibgo » 2018-06-23T00:44:41-07:00

So, your image has noise. You want to remove the noise while not removing detail. From such a small sample I can't tell what is noise and what is detail.

However, the median filter cleans this image:

Code: Select all

magick lines.pbm -statistic median 11x1 out.png
snibgo's IM pages: im.snibgo.com

Jean-Pierre Coulon
Posts: 41
Joined: 2016-10-04T02:08:22-07:00
Authentication code: 1151
Location: Nice, France

Re: Filter to improve some tif images

Post by Jean-Pierre Coulon » 2018-06-23T02:43:28-07:00

fmw42 wrote:
2018-06-22T22:31:50-07:00

Code: Select all

convert -version
will give you the ImageMagick version.
hey, there is an old version in your brains :-) Here it works only with magick -version and it says 7.0.5-0 Q8 x86
Last edited by Jean-Pierre Coulon on 2018-06-23T05:13:57-07:00, edited 1 time in total.

Jean-Pierre Coulon
Posts: 41
Joined: 2016-10-04T02:08:22-07:00
Authentication code: 1151
Location: Nice, France

Re: Filter to improve some tif images

Post by Jean-Pierre Coulon » 2018-06-23T03:25:45-07:00

snibgo wrote:
2018-06-23T00:44:41-07:00
So, your image has noise. You want to remove the noise while not removing detail. From such a small sample I can't tell what is noise and what is detail.
I would be happy if my 6th line was transformed into
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
However, the median filter cleans this image:

Code: Select all

magick lines.pbm -statistic median 11x1 out.png
Perfect for horizontal lines like my example, but does nothing for vertical lines and whitens some horizontal portions of vertical lines.

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

Re: Filter to improve some tif images

Post by snibgo » 2018-06-23T03:48:50-07:00

The median filter I show acts horizontally. If you want it to act vertically, interchange the dimensions: "-statistic median 1x11".

I suggest you post a link to entire images, not small portions.
snibgo's IM pages: im.snibgo.com

Jean-Pierre Coulon
Posts: 41
Joined: 2016-10-04T02:08:22-07:00
Authentication code: 1151
Location: Nice, France

Re: Filter to improve some tif images

Post by Jean-Pierre Coulon » 2018-06-23T17:39:25-07:00

You can obtain a test page like this: 1: scan 1 page of sheet music at 600 dpi, tif format, with an intentional skew of about 1 degree. Should be about 100 kB big. 2: say magick thispage.tif -deskew 50% newpage.tif. Should give an about 200 KB big page.

Magnify a portion of a staff line a lot and you will understand what I want to filter.

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

Re: Filter to improve some tif images

Post by fmw42 » 2018-06-23T20:42:28-07:00

It would be better if you provide an example. This forum does not allow uploads. So you need to post the image to some free image hosting service and then put the URL here.

Jean-Pierre Coulon
Posts: 41
Joined: 2016-10-04T02:08:22-07:00
Authentication code: 1151
Location: Nice, France

Re: Filter to improve some tif images

Post by Jean-Pierre Coulon » 2018-06-24T02:16:15-07:00

Then goto http://imslp.org/wiki/Clarinet_Quintet_ ... g_Amadeus) Search the viola part in the Scanned by Coulonnus section. Extract p.2 with pdftk. Say magick p2.pdf -quality 100% -density 600 p2.jpg and magick p2.jpg -threshold 50% -compress group4 p2.tif (for some reason a direct pdf to tif conversion gives a result with a very low density). p2.tif should be 123 577 B big. But all it will contain will be a big number of cases like line 6 of my brief pbm example.

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

Re: Filter to improve some tif images

Post by snibgo » 2018-06-24T02:17:04-07:00

Jean-Pierre Coulon wrote:... scan 1 page of sheet music ...
Scanning makes continuous-tone images (grayscale or colour). But your image is black and white only. Why?

If you must make it black and white only, I suggest you do that after denoising, not before.
snibgo's IM pages: im.snibgo.com

Jean-Pierre Coulon
Posts: 41
Joined: 2016-10-04T02:08:22-07:00
Authentication code: 1151
Location: Nice, France

Re: Filter to improve some tif images

Post by Jean-Pierre Coulon » 2018-06-24T06:14:04-07:00

snibgo wrote:
2018-06-24T02:17:04-07:00
Jean-Pierre Coulon wrote:... scan 1 page of sheet music ...
Scanning makes continuous-tone images (grayscale or colour). But your image is black and white only. Why?
Simply because a grayscale page would be about 10 times bigger than a monochrome. And the original document was monochrome.
If you must make it black and white only, I suggest you do that after denoising, not before.
Then is there the right filter for me in grayscale?

I succeeded in reducing the tif size by 75 % with my home made Fortran process.

Post Reply