Page 5 of 5

Re: Fred's ImageMagick Scripts

Posted: 2013-05-25T19:00:27-07:00
by fmw42
For anyone interested, it seems that Cygwin (or Window) is taking the \n that is automatically included with IM string formats and -fx escapes and putting that into the variable as \r\n. Cygwin unix apparently does not like the \r though properly ignores the \n.

In IM 6.8.5.8 the automatic \n has been removed from string formats and fx exscapes (though one can add it back in the command).

I will let you know further if some one can test 6.8.5.8 to see if the following now works correctly.

width=$(convert rose: -format "%w" info:)
echo "width=${width}"
xx=$((width-1))
echo "xx=${xx}"

Note that the following should work in older versions of IM.

width=$(convert rose: -format "%w" info: | tr -d "\r")
echo "width=${width}"
xx=$((width-1))
echo "xx=${xx}"

In order for my scripts to function in Cygwin (unmodified), one would need to have IM 6.8.5.8. Otherwise, any IM string format or fx escape stored in a variable will cause problems later in the script if the variable has any further integer calculations performed similar to the above.

Re: Fred's ImageMagick Scripts

Posted: 2013-06-02T19:29:05-07:00
by anthony
As of the latest IM, the end of line is no longer appended by default on the -format string.

as such you can now better control the EOL handling problem that was found in Cygwin.

However the real problem is in that BASH does not treat '\r' as whitespace in its mathematical expressions.
That I consider a bug, and probably should be reported to the BASH developers, even though it is normally
not a concern in UNIX environment.

Re: Fred's ImageMagick Scripts

Posted: 2013-06-02T19:43:36-07:00
by fmw42
As of IM 6.8.5.8, identify -format was still leaving in the \n whereas convert .. -format info: was not. This has been fixed in IM 6.8.5.9

compare also has \n removed in 6.8.5.9


Seems to me that it might be useful to have a MAGICK environment variable to allow the \n to be included or removed, whichever seems better so that it can be controlled by the user. That would allow the more visual \n mode to be used when one just wants results to the terminal, but then allow \n to be removed for computer analysis of results returned to variables. This would be especially useful for compare, since there is no way to add the \n back in for view on the terminal.

Re: Fred's ImageMagick Scripts

Posted: 2013-06-21T01:32:54-07:00
by Barruel
Hi.

I'm into the book scanning thing and I've recently came into IM, which has allowed me to automate almost every part of the process.

The only thing which I am doing now manually is extracting pictures from pages. I need to do this because I process the text (with IM) to b/w images, and I have to have the images separately in grayscale or color formats, so I can -composite the images over the text.

To do so, I crop the pictures to a new layer (using GIMP), and remove afterwards the background layer, so the picture is left lying over a transparent background. This transparent background is what gets filled with the b/w text after -composite.

To do this, in need the pictures to stay in their original position in the page.

I've come to the Multicrop script and found it EXTREMELY good (kudos!) at finding and extracting the pictures, but I can't get it to output the images over a transparent background. It just extracts the images.

The mask output does something similar to what I'm trying to do. So, is there a way to extract the images WHILE keeping them in their position in the original page layout? Does any other of the Fred's scripts do this? I've searched, but I have been unsuccessful so far.

Best regards.

Edit:

Code: Select all

$ identify -version
Version: ImageMagick 6.7.6-3 2012-04-28 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP
Running in Cygwin under Windows XP.

Re: Fred's ImageMagick Scripts

Posted: 2013-06-21T06:58:23-07:00
by Barruel
Ok.

I've got my images correctly placed over a black background by removing the -trim in the line 385:

Code: Select all

			# Then trim and deskew/unrotate to make the output.
			if [ $unrotate -eq 1 -o $unrotate -eq 3 ]; then
				convert $tmpA1 $tmpA4 -compose multiply -composite \
					-fuzz ${fuzzval}% -trim -background "$bcolor" $derotate \         <------ this one
					-compose over -bordercolor "$bcolor" -border 2 -trim +repage \
					${outname}-${k}.${suffix}
Now I have to find a way to make that black background transparent.

However, I see a problem arising when there are more than one images in a page, as every detected image is saved separatedly in a numbered sequence.

I think that it would be interesting having the images-in-their-layout as a new output mode.

Best regards.

Re: Fred's ImageMagick Scripts

Posted: 2013-06-21T09:01:21-07:00
by Barruel
Barruel wrote:Now I have to find a way to make that black background transparent.
Done. Got it from here.

Code: Select all

convert tool.png -bordercolor white -border 1x1 -matte -fill none -fuzz 7% -draw 'matte 1,1 floodfill' -shave 1x1 white_floodfill.png