How to slice up image of text
Re: How to slice up image of text
I think we are going in circles - you told me you can't just move the folder because of the windows registry keys, and I tried to reinstall but it won't let me select any other folder to install to (thus my other post about not being able to install the software to another folder). Do you have any ideas of how else to fix it since I can't use the installer?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How to slice up image of text
Now you are getting me confused. Currently, your IM doesn't work, because you moved its files. Is that correct? So move the files back where they were. I suspect IM will then work. If not, then just reinstall. True, that will be to the original directory with a space (because of the installation bug), but that's not a major problem.
Next, if you haven't already, create a directory you will do your work in. (For various reasons, doing work in the same directory that contains IM isn't a good idea.) This directory could be "\mywork\thisproject" or anything else you like, but with no spaces.
Next, "cd" to that directory, and copy or move your images to there.
Next, run the scripts.
Next, if you haven't already, create a directory you will do your work in. (For various reasons, doing work in the same directory that contains IM isn't a good idea.) This directory could be "\mywork\thisproject" or anything else you like, but with no spaces.
Next, "cd" to that directory, and copy or move your images to there.
Next, run the scripts.
snibgo's IM pages: im.snibgo.com
Re: How to slice up image of text
No I never moved it, I just copied the folder to the root directory. It isn't working because of the space in the first directory, you can tell by looking at the errors. Question, how do you use the "magick" command if you aren't in the directory that contains "magick"?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How to slice up image of text
I've already told you this:damonm wrote:Question, how do you use the "magick" command if you aren't in the directory that contains "magick"?
snibgo wrote:I suggest you run the script from a directory that has no spaces.
From that other directory, check that magick.exe is still on your path:This should show the version number. But if you get an error message like:Code: Select all
magick -version
... then you can temporarily add magick's directory to your system path:Code: Select all
'magick' is not recognized as an internal or external command, operable program or batch file.
Code: Select all
set PATH=C:\Program Files\ImageMagick-7.0.5-Q16;%PATH%
snibgo's IM pages: im.snibgo.com
Re: How to slice up image of text
Good news, progress is occurring but I need your assistance again! Check out the below - everything is now running, right up until we get to where it runs "sed"- which is in another directory so I don't think it's finding it and I'm not sure how to fix that. I tried creating another "set sed=C:\"program files\blah\blah" but that didn't work for me when I ran it the second time. The next error after sed, is when it calls "echoRestore" which it says is not a recognized command or batch file. Do you know why it suddenly wouldn't be able to find that directory again?
Many thanks, we are almost there!
c:\Images>call %PICTBAT%guillotine.bat pat_crp.png subs_XX.png White 2 . 1
c:\Images>rem From image pat_crp.png, guillotines into pieces.
c:\Images>set PICTBAT=C:"\Program Files\ImageMagick-7.0.5-Q16\pictbat\"
c:\Images>rem @call echoOffSave
c:\Images>call C:"\Program Files\ImageMagick-7.0.5-Q16\pictbat\"setInOut pat_crp
.png guil
c:\Images>setlocal DisableDelayedExpansion
c:\Images>set INFILE=c:\Images\pat_crp.png
c:\Images>if not exist "c:\Images\pat_crp.png" set INFILE=pat_crp.png
c:\Images>endlocal & set INFILE=c:\Images\pat_crp.png
c:\Images>setlocal DisableDelayedExpansion
c:\Images>if "" == "1" (
echo INFILE=c:\Images\pat_crp.png
echo INFILEBANG=c:\Images\pat_crp.png
echo OUTFILE=c:\Images\pat_crp_guil.png
echo INNAME=pat_crp
echo BASENAME=c:\Images\pat_crp
echo EXT=.png
)
c:\Images>endlocal
c:\Images>if not "subs_XX.png" == "" if not "subs_XX.png" == "." set OUTFILE=sub
s_XX.png
c:\Images>call C:"\Program Files\ImageMagick-7.0.5-Q16\pictbat\"guilFind pat_crp
.png . White 2 . 1
c:\Images>rem From image pat_crp.png, returns list of ordinates to guillotine in
to pieces.
c:\Images>set PICTBAT=\pictbat\
c:\Images>rem @call echoOffSave
c:\Images>call \pictbat\setInOut pat_crp.png guil
The system cannot find the path specified.
c:\Images>for /F %F in ("subs_XX.png") do set OUTFILE=%~dpnF.lis
c:\Images>set OUTFILE=c:\Images\subs_XX.lis
c:\Images>if not "." == "" if not "." == "." set OUTFILE=.
c:\Images>set TMPTXT1=c:\Images\pat_crp_guil1.lis
c:\Images>set TMPTXT2=c:\Images\pat_crp_guil2.lis
c:\Images>set TEMP_IMG=c:\Images\pat_crp_guil.png
c:\Images>set BACK_COL=White
c:\Images>if "White" == "." set BACK_COL=
c:\Images>if "White" == "" set BACK_COL=White
c:\Images>set FUZZ=2
c:\Images>if "2" == "." set FUZZ=
c:\Images>if "2" == "" set FUZZ=0
c:\Images>set NON_BACK=.
c:\Images>if "." == "." set NON_BACK=
c:\Images>if "" == "" set NON_BACK=0
c:\Images>set DIRN=1
c:\Images>if "1" == "." set DIRN=
c:\Images>if "1" == "" set DIRN=0
c:\Images>if 1 == 0 (
set ROT_IN=
set ROT_OUT=
) else (
set ROT_IN=-rotate -90
set ROT_OUT=-rotate 90
)
c:\Images>if 2 == 0 (set sFUZZ= ) else (set sFUZZ=-fuzz 2% )
c:\Images>Magick convert c:\Images\pat_crp.png -strip -rotate -90 -fuzz
2% -alpha set -transparent White -channel RGB -evaluate set 100% +channel
-background Black -layers Flatten -scale "x1^!" -fuzz 0% -fill Black -op
aque Black -fill White +opaque Black c:\Images\pat_crp_guil.png
c:\Images>if not "" == "" (
set /A MG=/2
magick convert c:\Images\pat_crp_guil.png -negate -morphology Dista
nce:-1 Chebyshev:1,1 -black-threshold !MG! -fill White +opaque Black
-negate c:\Images\pat_crp_guil.png
)
c:\Images>if "" == "1" magick convert c:\Images\pat_crp_guil.png -negate -
morphology Distance:-1 Chebyshev:1,1 -auto-level -fill Black +opaque White
-negate c:\Images\pat_crp_guil.png
c:\Images>for /F "usebackq tokens=3 delims=x+" %C in (`magick convert c:\Image
s\pat_crp_guil.png -quiet -bordercolor Black -border 1 -format "%@" info
:`) do (set /A OFFSET=%C-1 )
c:\Images>(set /A OFFSET=193-1 )
c:\Images>echo guilFind: OFFSET=192
guilFind: OFFSET=192
c:\Images>magick convert c:\Images\pat_crp_guil.png -quiet -crop 0x1+192+0
+repage -morphology Thicken:-1 Skeleton -transparent White sparse-color:c
:\Images\pat_crp_guil1.lis
c:\Images>sed -e 's/ /\n/g' c:\Images\pat_crp_guil1.lis 1>c:\Images\pat_crp_gui
l2.lis
'sed' is not recognized as an internal or external command,
operable program or batch file.
c:\Images>type c:\Images\pat_crp_guil2.lis
c:\Images>set nCUTS=0
c:\Images>(for /F "tokens=1 delims=, " %X in (c:\Images\pat_crp_guil2.lis) do (
set /A V=%X+192
echo !V!
set /A nCUTS+=1
) ) 1>c:\Images\subs_XX.lis
c:\Images>echo guilFind: nCUTS=0
guilFind: nCUTS=0
c:\Images>type c:\Images\subs_XX.lis
c:\Images>call echoRestore
'echoRestore' is not recognized as an internal or external command,
operable program or batch file.
c:\Images>endlocal & set guilOUTFILE=c:\Images\subs_XX.lis & set guilNUM_CUTS
=0
c:\Images>if ERRORLEVEL 1 exit /B 1
c:\Images>
Many thanks, we are almost there!
c:\Images>call %PICTBAT%guillotine.bat pat_crp.png subs_XX.png White 2 . 1
c:\Images>rem From image pat_crp.png, guillotines into pieces.
c:\Images>set PICTBAT=C:"\Program Files\ImageMagick-7.0.5-Q16\pictbat\"
c:\Images>rem @call echoOffSave
c:\Images>call C:"\Program Files\ImageMagick-7.0.5-Q16\pictbat\"setInOut pat_crp
.png guil
c:\Images>setlocal DisableDelayedExpansion
c:\Images>set INFILE=c:\Images\pat_crp.png
c:\Images>if not exist "c:\Images\pat_crp.png" set INFILE=pat_crp.png
c:\Images>endlocal & set INFILE=c:\Images\pat_crp.png
c:\Images>setlocal DisableDelayedExpansion
c:\Images>if "" == "1" (
echo INFILE=c:\Images\pat_crp.png
echo INFILEBANG=c:\Images\pat_crp.png
echo OUTFILE=c:\Images\pat_crp_guil.png
echo INNAME=pat_crp
echo BASENAME=c:\Images\pat_crp
echo EXT=.png
)
c:\Images>endlocal
c:\Images>if not "subs_XX.png" == "" if not "subs_XX.png" == "." set OUTFILE=sub
s_XX.png
c:\Images>call C:"\Program Files\ImageMagick-7.0.5-Q16\pictbat\"guilFind pat_crp
.png . White 2 . 1
c:\Images>rem From image pat_crp.png, returns list of ordinates to guillotine in
to pieces.
c:\Images>set PICTBAT=\pictbat\
c:\Images>rem @call echoOffSave
c:\Images>call \pictbat\setInOut pat_crp.png guil
The system cannot find the path specified.
c:\Images>for /F %F in ("subs_XX.png") do set OUTFILE=%~dpnF.lis
c:\Images>set OUTFILE=c:\Images\subs_XX.lis
c:\Images>if not "." == "" if not "." == "." set OUTFILE=.
c:\Images>set TMPTXT1=c:\Images\pat_crp_guil1.lis
c:\Images>set TMPTXT2=c:\Images\pat_crp_guil2.lis
c:\Images>set TEMP_IMG=c:\Images\pat_crp_guil.png
c:\Images>set BACK_COL=White
c:\Images>if "White" == "." set BACK_COL=
c:\Images>if "White" == "" set BACK_COL=White
c:\Images>set FUZZ=2
c:\Images>if "2" == "." set FUZZ=
c:\Images>if "2" == "" set FUZZ=0
c:\Images>set NON_BACK=.
c:\Images>if "." == "." set NON_BACK=
c:\Images>if "" == "" set NON_BACK=0
c:\Images>set DIRN=1
c:\Images>if "1" == "." set DIRN=
c:\Images>if "1" == "" set DIRN=0
c:\Images>if 1 == 0 (
set ROT_IN=
set ROT_OUT=
) else (
set ROT_IN=-rotate -90
set ROT_OUT=-rotate 90
)
c:\Images>if 2 == 0 (set sFUZZ= ) else (set sFUZZ=-fuzz 2% )
c:\Images>Magick convert c:\Images\pat_crp.png -strip -rotate -90 -fuzz
2% -alpha set -transparent White -channel RGB -evaluate set 100% +channel
-background Black -layers Flatten -scale "x1^!" -fuzz 0% -fill Black -op
aque Black -fill White +opaque Black c:\Images\pat_crp_guil.png
c:\Images>if not "" == "" (
set /A MG=/2
magick convert c:\Images\pat_crp_guil.png -negate -morphology Dista
nce:-1 Chebyshev:1,1 -black-threshold !MG! -fill White +opaque Black
-negate c:\Images\pat_crp_guil.png
)
c:\Images>if "" == "1" magick convert c:\Images\pat_crp_guil.png -negate -
morphology Distance:-1 Chebyshev:1,1 -auto-level -fill Black +opaque White
-negate c:\Images\pat_crp_guil.png
c:\Images>for /F "usebackq tokens=3 delims=x+" %C in (`magick convert c:\Image
s\pat_crp_guil.png -quiet -bordercolor Black -border 1 -format "%@" info
:`) do (set /A OFFSET=%C-1 )
c:\Images>(set /A OFFSET=193-1 )
c:\Images>echo guilFind: OFFSET=192
guilFind: OFFSET=192
c:\Images>magick convert c:\Images\pat_crp_guil.png -quiet -crop 0x1+192+0
+repage -morphology Thicken:-1 Skeleton -transparent White sparse-color:c
:\Images\pat_crp_guil1.lis
c:\Images>sed -e 's/ /\n/g' c:\Images\pat_crp_guil1.lis 1>c:\Images\pat_crp_gui
l2.lis
'sed' is not recognized as an internal or external command,
operable program or batch file.
c:\Images>type c:\Images\pat_crp_guil2.lis
c:\Images>set nCUTS=0
c:\Images>(for /F "tokens=1 delims=, " %X in (c:\Images\pat_crp_guil2.lis) do (
set /A V=%X+192
echo !V!
set /A nCUTS+=1
) ) 1>c:\Images\subs_XX.lis
c:\Images>echo guilFind: nCUTS=0
guilFind: nCUTS=0
c:\Images>type c:\Images\subs_XX.lis
c:\Images>call echoRestore
'echoRestore' is not recognized as an internal or external command,
operable program or batch file.
c:\Images>endlocal & set guilOUTFILE=c:\Images\subs_XX.lis & set guilNUM_CUTS
=0
c:\Images>if ERRORLEVEL 1 exit /B 1
c:\Images>
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How to slice up image of text
On sed, as I said earlier:
Other versions of sed are available, such as http://gnuwin32.sourceforge.net/packages/sed.htm
Wherever you get sed from, you need to install it to a directory on your system path, or add that directory to your system path.
On echoRestore, see my page http://im.snibgo.bat/zipbats.htm , which explains that echoRestore.bat (and others) should be in a directory that is on your system path. These are generic scripts, not specific to image processing. If you prefer, yo could put them in %PICTBAT%, but then you should prefix calls to those scripts with %PICTBAT%, such as:
If you haven't installed sed, then you haven't got it. I use the Cygwin version, because Cygwin contains loads of other useful stuff, like bash. See my page http://im.snibgo.bat/cygwin.htm .snibgo wrote:"sed" is a utility program, available from the Cygwin installation (and probably many other places).
Other versions of sed are available, such as http://gnuwin32.sourceforge.net/packages/sed.htm
Wherever you get sed from, you need to install it to a directory on your system path, or add that directory to your system path.
On echoRestore, see my page http://im.snibgo.bat/zipbats.htm , which explains that echoRestore.bat (and others) should be in a directory that is on your system path. These are generic scripts, not specific to image processing. If you prefer, yo could put them in %PICTBAT%, but then you should prefix calls to those scripts with %PICTBAT%, such as:
Code: Select all
call %PICTBAT%echoRestore
snibgo's IM pages: im.snibgo.com
Re: How to slice up image of text
I know you said it earlier, and back when you said it I installed the gnuwin32 version. It defaulted to install to c:\program files (x86)\gnuwin32 and the sed file is located in the bin folder of that directory. Are you saying I should uninstall it and reinstall it to c:\program files\imagemagick-7.0.5-Q16 (which is the "PATH" that I have set)?
I'm also a bit confused because echoRestore is in a subdirectory of the PATH called PICTBAT which you had me create a shortcut to. Using the settings that I have it's able to call guilFind.bat etc that are also located there, but fails when it tries to call echoRestore. I actually tried editing the script, but it still said it couldn't locate it. I'm wondering if the PATH gets reset somewhere else in the script?
I'll play with it some more and see what I can come up with but your guidance on the SED would great, thanks.
I'm also a bit confused because echoRestore is in a subdirectory of the PATH called PICTBAT which you had me create a shortcut to. Using the settings that I have it's able to call guilFind.bat etc that are also located there, but fails when it tries to call echoRestore. I actually tried editing the script, but it still said it couldn't locate it. I'm wondering if the PATH gets reset somewhere else in the script?
I'll play with it some more and see what I can come up with but your guidance on the SED would great, thanks.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How to slice up image of text
On sed: If you've installed sed to c:\program files (x86)\gnuwin32, then just add that path to your system path, just like you did with IM's directory, for example:
[EDIT: you said it is bin of that directory, so you need bin in the path.]
But this is a temporary change. It only applies to that window. If you reboot, you'll need to do this again.
You can change the system path in way that survive reboots etc. (Control panel, "environment variables".) But this is drifting far from ImageMagick.
On echoRestore:
Code: Select all
set PATH=c:\program files (x86)\gnuwin32\bin;%PATH%
But this is a temporary change. It only applies to that window. If you reboot, you'll need to do this again.
You can change the system path in way that survive reboots etc. (Control panel, "environment variables".) But this is drifting far from ImageMagick.
On echoRestore:
What does that line of the script say now?damonm wrote:I actually tried editing the script, but it still said it couldn't locate it.
No. My scripts don't modify PATH. But it will get reset on reboot to the global value. (Control panel, "environment variables".)damonm wrote:I'm wondering if the PATH gets reset somewhere else in the script?
snibgo's IM pages: im.snibgo.com
Re: How to slice up image of text
It seems to be working now, right up to the end where it calls guilchop - I think I need to find it and modify that call but I can't find what file it's in, do you know what file it's in?
c:\Images>echo guilFind: nCUTS=0
guilFind: nCUTS=0
c:\Images>type c:\Images\subs_XX.lis
c:\Images>call echoRestore
ECHO is on.
c:\Images>endlocal & set guilOUTFILE=c:\Images\subs_XX.lis & set guilNUM_CUTS
=0
c:\Images>if ERRORLEVEL 1 exit /B 1
c:\Images>call \pictbat\guilChop pat_crp.png c:\Images\subs_XX.lis subs_XX.png 1
The system cannot find the path specified.
c:\Images>if ERRORLEVEL 1 exit /B 1
c:\Images>echo guilFind: nCUTS=0
guilFind: nCUTS=0
c:\Images>type c:\Images\subs_XX.lis
c:\Images>call echoRestore
ECHO is on.
c:\Images>endlocal & set guilOUTFILE=c:\Images\subs_XX.lis & set guilNUM_CUTS
=0
c:\Images>if ERRORLEVEL 1 exit /B 1
c:\Images>call \pictbat\guilChop pat_crp.png c:\Images\subs_XX.lis subs_XX.png 1
The system cannot find the path specified.
c:\Images>if ERRORLEVEL 1 exit /B 1
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How to slice up image of text
At the top of what you have pasted:
It has found no cuts at all. That's a problem that needs fixing. There is probably something earlier, that you haven't shown, explaining the problem.damonm wrote:guilFind: nCUTS=0
The call is made in guillotine.bat.damonm wrote:c:\Images>call \pictbat\guilChop pat_crp.png c:\Images\subs_XX.lis subs_XX.png 1
The system cannot find the path specified.
snibgo's IM pages: im.snibgo.com
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How to slice up image of text
I've realised the scripts need echo to be turned off. When it is on, they echo commands to data files, and this screws up the process.
So, in guillotine.bat and guilFind.bat and guilChop.bat, near the top, I suggested you prefix the ...
... line in each file with "rem". Try removing "rem", and re-running.
The text output should look something like this:
So, in guillotine.bat and guilFind.bat and guilChop.bat, near the top, I suggested you prefix the ...
Code: Select all
@call echoOffSave
The text output should look something like this:
Code: Select all
f:\web\im>rem From image pat_crp.png, guillotines into pieces.
guilFind: OFFSET=29
47,0,graya(0,1)
76,0,graya(0,1)
117,0,graya(0,1)
156,0,graya(0,1)
196,0,graya(0,1)
245,0,graya(0,1)
294,0,graya(0,1)
333,0,graya(0,1)
372,0,graya(0,1)
411,0,graya(0,1)
450,0,graya(0,1)
489,0,graya(0,1)
529,0,graya(0,1)
675,0,graya(0,1)
758,0,graya(0,1)
guilFind: nCUTS=15
76
105
146
185
225
274
323
362
401
440
479
518
558
704
787
c:\im\ImageMagick-6.9.5-3-Q16\convert f:\web\im\pat_crp.png -rotate -90 ^
( +clone -crop 77x+0+0 +repage -rotate 90 -write subs_0.png +delete ) ^
( +clone -crop 29x+77+0 +repage -rotate 90 -write subs_1.png +delete ) ^
( +clone -crop 41x+106+0 +repage -rotate 90 -write subs_2.png +delete ) ^
( +clone -crop 39x+147+0 +repage -rotate 90 -write subs_3.png +delete ) ^
( +clone -crop 40x+186+0 +repage -rotate 90 -write subs_4.png +delete ) ^
( +clone -crop 49x+226+0 +repage -rotate 90 -write subs_5.png +delete ) ^
( +clone -crop 49x+275+0 +repage -rotate 90 -write subs_6.png +delete ) ^
( +clone -crop 39x+324+0 +repage -rotate 90 -write subs_7.png +delete ) ^
( +clone -crop 39x+363+0 +repage -rotate 90 -write subs_8.png +delete ) ^
( +clone -crop 39x+402+0 +repage -rotate 90 -write subs_9.png +delete ) ^
( +clone -crop 39x+441+0 +repage -rotate 90 -write subs_10.png +delete ) ^
( +clone -crop 39x+480+0 +repage -rotate 90 -write subs_11.png +delete ) ^
( +clone -crop 40x+519+0 +repage -rotate 90 -write subs_12.png +delete ) ^
( +clone -crop 146x+559+0 +repage -rotate 90 -write subs_13.png +delete ) ^
( +clone -crop 83x+705+0 +repage -rotate 90 -write subs_14.png +delete ) ^
( +clone -crop +788+0 +repage -rotate 90 -write subs_15.png ) ^
NULL:
f:\web\im>endlocal & set guilOUTFILE=subs_XX.png & set guilNUM_CUTS=15
snibgo's IM pages: im.snibgo.com
Re: How to slice up image of text
I made those changes, now it says this and it's just a blinking cursor, thoughts?
c:\Images>call %PICTBAT%guillotine.bat pat_crp.png subs_XX.png White 2 . 1
c:\Images>rem From image pat_crp.png, guillotines into pieces.
guilFind: OFFSET=192
sed: -e expression #1, char 1: unknown command: `''
guilFind: nCUTS=0
c:\Images>call %PICTBAT%guillotine.bat pat_crp.png subs_XX.png White 2 . 1
c:\Images>rem From image pat_crp.png, guillotines into pieces.
guilFind: OFFSET=192
sed: -e expression #1, char 1: unknown command: `''
guilFind: nCUTS=0
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to slice up image of text
Looks like you do not have sed installed.
Re: How to slice up image of text
I do have sed installed..... maybe I need to use the exact same version you have?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How to slice up image of text
Sed is running, but complaining.damonm wrote:sed: -e expression #1, char 1: unknown command: `''
The sed line in guilFind.bat should be:
Code: Select all
sed -e 's/ /\n/g' %TMPTXT1% >%TMPTXT2%
For me, double-quotes work as well as single quotes. If that doesn't help, I suggest you read the documentation on your sed. Perhaps "sed --help" will help.
snibgo's IM pages: im.snibgo.com