Straightening and cropping images

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Straightening and cropping images

Luba Polyak
Hello Imagej users,

I am new to the community and to Java. I currently work in a rare books
library on a project to digitize rare books and to make them available
online.

My job is to ''process'' the images -- basically to straighten the image by
the inner seam of the book and then to add a crop around the borders of the
visible page. Some of the books are shot open (such that both pages are
visible) and some are shot recto/verso (such that only one page is visible
per image). As you can imagine, this takes forever to do by hand and it
seems that ImageJ could work as a way to automate the process.

I was hoping you could recommend some documentation/reading on how to do
this, plug ins you think may work well, or even a reference to someone who
has done a similar project. Thanks for any help you could offer!

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Straightening and cropping images

Alan Hewat
You may already know that Adobe Acrobat (the expensive version, not
the free Reader) can scan documents, automatically straighten the
pages and interpret the text. It can also work with pre-scanned
images, but it is not a good idea to have different people doing the
different steps, since scanning parameters must be adjusted for
maximum legibility.

You should also check that Google Scholar has not already scanned the
book :-) They have a project to scan everything.  Although the Google
book may only appear as a scanned copy on the WWW, you can download
the actual PDF including machine readable text using the "Google Book
Downloader". Google's text recognition is better than you can do from
the scanned image, even using Adobe Acrobat in my personal experience.

Alan

On 14 January 2013 22:48, Luba Polyak <[hidden email]> wrote:

> Hello Imagej users,
>
> I am new to the community and to Java. I currently work in a rare books
> library on a project to digitize rare books and to make them available
> online.
>
> My job is to ''process'' the images -- basically to straighten the image by
> the inner seam of the book and then to add a crop around the borders of the
> visible page. Some of the books are shot open (such that both pages are
> visible) and some are shot recto/verso (such that only one page is visible
> per image). As you can imagine, this takes forever to do by hand and it
> seems that ImageJ could work as a way to automate the process.
>
> I was hoping you could recommend some documentation/reading on how to do
> this, plug ins you think may work well, or even a reference to someone who
> has done a similar project. Thanks for any help you could offer!
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
______________________________________________
Dr Alan Hewat, NeutronOptics, Grenoble, FRANCE
<[hidden email]> +33.476.98.41.68
        http://www.NeutronOptics.com/hewat
______________________________________________

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Straightening and cropping images

Chuck Harrison-2
In reply to this post by Luba Polyak
Luba,

I am sure that ImageJ could do a good job of text deskewing, but I am
not aware of any ImageJ tools written specifically for that task. For
alternatives you might look at http://galfar.vevb.net/wp/tag/deskew/ ,
and also check out postings at
http://www.diybookscanner.org/forum/viewforum.php?f=20

Regards,
  Chuck


On Mon, Jan 14, 2013 at 1:48 PM, Luba Polyak <[hidden email]> wrote:

> Hello Imagej users,
>
> I am new to the community and to Java. I currently work in a rare books
> library on a project to digitize rare books and to make them available
> online.
>
> My job is to ''process'' the images -- basically to straighten the image by
> the inner seam of the book and then to add a crop around the borders of the
> visible page. Some of the books are shot open (such that both pages are
> visible) and some are shot recto/verso (such that only one page is visible
> per image). As you can imagine, this takes forever to do by hand and it
> seems that ImageJ could work as a way to automate the process.
>
> I was hoping you could recommend some documentation/reading on how to do
> this, plug ins you think may work well, or even a reference to someone who
> has done a similar project. Thanks for any help you could offer!
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Straightening and cropping images

Michael Schmid
Hi Luba,

following the idea of the deskew program mentioned by Chuck (at http://galfar.vevb.net/wp/tag/deskew/ ), you could do something similar in ImageJ to determine the rotation angle.
It will work for pages with mainly text, not for images.

You need the Polar Transformer plugin from http://rsbweb.nih.gov/ij/plugins/polar-transformer.html.

Here is a macro for it - beware of line breaks caused by the mailer.

origId=getImageID();
run("Duplicate...", "title=[temp]");
tempId=getImageID();
run("North");
run("FFT");
FFTid=getImageID();
selectImage(tempId);
close();
selectImage(FFTid);
run("Polar Transformer", "method=Polar degrees=360 default number=3600");
newWidth=round(getWidth()/3);
run("Canvas Size...", "width=&newWidth height=1800 position=Bottom-Center zero");
run("Bin...", "x=&newWidth y=1 bin=Average");
run("Clear Results");
run("Find Maxima...", "noise=10000 output=List");
close();
selectImage(FFTid);
close();
angle=-(0.1*getResult("Y", 0)-90);
print("angle="+angle);
selectImage(origId);
run("Rotate... ", "angle=&angle grid=1 interpolation=Bilinear fill");


For more information on macros, see
  http://rsb.info.nih.gov/ij/developer/macro/macros.html   and
  http://rsb.info.nih.gov/ij/developer/macro/functions.html

The macro uses 0.1 degree resolution (3600 angle increments); this could be easily changed.

For better accuracy (without further decreasing the angle increment):
- On could replace 'find maxima' by something better (with subpixel accuracy)
- Using the Power Spectrum (FFT Options) rather then the log plot of FFT intensity might be better. When using the power spectrum, one may also have a look what a 'typical' height of the maximum is, and ask the user to unrotate it manually if that value is too low (e.g. because the page is mostly blank).

For higher speed, add at the beginning: SetBatchMode(true);

For automatically applying the macro to all files in a directory: Process>Batch>Macro
--

For cropping, if all pages are identical, simply use the macro recorder: Do it manually, and record your steps as a macro.
The easiest way to split two adjacent pages is Image>Stacks>Tools>Montage to Stack.


Michael
________________________________________________________________
On Jan 15, 2013, at 18:25, Chuck Harrison wrote:

> Luba,
>
> I am sure that ImageJ could do a good job of text deskewing, but I am
> not aware of any ImageJ tools written specifically for that task. For
> alternatives you might look at http://galfar.vevb.net/wp/tag/deskew/ ,
> and also check out postings at
> http://www.diybookscanner.org/forum/viewforum.php?f=20
>
> Regards,
>  Chuck
>
>
> On Mon, Jan 14, 2013 at 1:48 PM, Luba Polyak <[hidden email]> wrote:
>> Hello Imagej users,
>>
>> I am new to the community and to Java. I currently work in a rare books
>> library on a project to digitize rare books and to make them available
>> online.
>>
>> My job is to ''process'' the images -- basically to straighten the image by
>> the inner seam of the book and then to add a crop around the borders of the
>> visible page. Some of the books are shot open (such that both pages are
>> visible) and some are shot recto/verso (such that only one page is visible
>> per image). As you can imagine, this takes forever to do by hand and it
>> seems that ImageJ could work as a way to automate the process.
>>
>> I was hoping you could recommend some documentation/reading on how to do
>> this, plug ins you think may work well, or even a reference to someone who
>> has done a similar project. Thanks for any help you could offer!
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Straightening and cropping images

Gabriel Landini
On Tuesday 15 Jan 2013 19:35:08 you wrote:
> following the idea of the deskew program mentioned by Chuck (at
> http://galfar.vevb.net/wp/tag/deskew/ ), you could do something similar in
> ImageJ to determine the rotation angle. It will work for pages with mainly
> text, not for images.
>
> You need the Polar Transformer plugin from
> http://rsbweb.nih.gov/ij/plugins/polar-transformer.html.
>
> Here is a macro for it - beware of line breaks caused by the mailer.

That is a very nice macro, many thanks Michael.

In my setup, however, the macro rotates the image but the angle seems to have
the wrong sign. E.g. in an artificially rotated image 15 degree to the right,
the result is rotated another 15 degrees to the right (rather than to the
left).
I think that it has to be "-angle", i.e. to get the image aligned properly I
need to remove the "-" from this line:

angle=-(0.1*getResult("Y", 0)-90);

so it reads

angle=(0.1*getResult("Y", 0)-90);

Cheers

Gabriel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Straightening and cropping images

Michael Schmid
On Jan 16, 2013, at 10:10, Gabriel Landini wrote:

> In my setup, however, the macro rotates the image but the angle seems to have
> the wrong sign.


Hi everone,

after some off-list discussion with Gabriel:
My macro [see previous post
  https://list.nih.gov/cgi-bin/wa.exe?A2=ind1301&L=IMAGEJ&F=&S=&P=78980   ]
needs the current version of the PolarTransformer from the ImageJ web site.

With the old version (early 2008 or previous) it rotates in the wrong direction.

If the images have a white background, and you don't have it like this by default, add the following at the beginning:
  setBackgroundColor(255,255,255);

Michael
________________________________________________________________
Michael Schmid                    email: [hidden email]
Institut für Angewandte Physik, Technische Universität Wien
Wiedner Hauptstr. 8-10/E134, A 1040 Wien, Austria
Tel. +43 1 58801-13452 or -13453, Fax +43 1 58801 13499
________________________________________________________________

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Straightening and cropping images

Antoinette
Please refer to following image cropping methods developed within visual basic.net application to crop an area from source image file.


Public Shared Function ApplyCrop(img As REImage, x As Integer, y As Integer, width As Integer, height As Integer) As Integer
End Function