Cutting a black part around grey paper

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

Cutting a black part around grey paper

Richard Kadot
Hello,
I am new on this site.
I need to process 4000 pictures.
They are old written letters between 1910 and 1950. Small and large, many sizes.
I scan in grey level with a black paper background.
Is it possible to create or find a macro to "cut around" the black background ?

Where do I search ?

Regards,
Richard K.

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

Re: Cutting a black part around grey paper

Herbie
Good day Richard,

project each scan in x and y, which gives you two mean 1D profiles.
In both profiles determine the two greatest gray transitions, that
should give you the coordinates of the document, even if your black
background isn't perfectly black.

With these four coordinates you can select the document in your scan and
crop it accordingly.

The whole processing can be done by an ImageJ-macro. Macro coding is
described in documents you will find at <https://imagej.nih.gov/ij/>.

HTH

Herbie

:::::::::::::::::::::::::::::::::::::::::::
Am 16.09.16 um 11:00 schrieb Richard Kadot:

> Hello,
> I am new on this site.
> I need to process 4000 pictures.
> They are old written letters between 1910 and 1950. Small and large, many sizes.
> I scan in grey level with a black paper background.
> Is it possible to create or find a macro to "cut around" the black background ?
>
> Where do I search ?
>
> Regards,
> Richard K.
>
> --
> 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: Cutting a black part around grey paper

Herbie
In reply to this post by Richard Kadot
Richard,

here is an ImageJ-macro that should do what you want...

/////////////////////////////////////////////////////////
setBatchMode( true );
   
run( "Select All" );
projection = getProfile();
diffArray( projection );
extrema = Array.findMaxima( projection, 0 );
x = extrema[0];
extrema = Array.findMinima( projection, 0 );
width = extrema[0] - x;
x++;
   
setKeyDown( "alt" );
projection = getProfile();
diffArray( projection );
extrema = Array.findMaxima( projection, 0 );
y = extrema[0];
extrema = Array.findMinima( projection, 0 );
height = extrema[0] - y;
y++;
   
run("Select None");
makeRectangle( x, y, width, height );
run("Crop");

setBatchMode( false );
exit();

function diffArray( a ) {
    for ( i = 1; i < a.length; i++ ) {
      a[i-1] = a[i] - a[i-1];
    }
    a[a.length-1] = 0;
}
/////////////////////////////////////////////////////////

HTH

Herbie