Dectecting and extracting pictures in a 1-layer image

72 Views Asked by At

I have an image which includes some pictures (of different sizes here and there) over a solid white background, all in 1 layer.

Can I isolate/extract all the pictures with photoshop ?

Thank you in advance,

1

There are 1 best solutions below

0
On

Yes and no. Working out where each of the individual images are would be quite difficult (and could involve a slow complex process of scanning each pixel)

But there is a way around it! Without seeing what these images look like, we assume that

  • The overall image is all one layer.
  • The individual images are rectangular
  • The individual images do not contain any white on the border

With that you can select magic wand in the top left, invert the selection and cut the images out.

//select top left hand corner
magicWand(0,0);

// inverse selection
activeDocument.selection.invert();

//copy image
activeDocument.selection.cut();

function magicWand(x,y)
{
    var id4109 = charIDToTypeID( "setd" );
    var desc623 = new ActionDescriptor();
    var id4110 = charIDToTypeID( "null" );
    var ref398 = new ActionReference();
    var id4111 = charIDToTypeID( "Chnl" );
    var id4112 = charIDToTypeID( "fsel" );
    ref398.putProperty( id4111, id4112 );
    desc623.putReference( id4110, ref398 );
    var id4113 = charIDToTypeID( "T   " );
    var desc624 = new ActionDescriptor();
    var id4114 = charIDToTypeID( "Hrzn" );
    var id4115 = charIDToTypeID( "#Pxl" );
    desc624.putUnitDouble( id4114, id4115, x );
    var id4116 = charIDToTypeID( "Vrtc" );
    var id4117 = charIDToTypeID( "#Pxl" );
    desc624.putUnitDouble( id4116, id4117, y );
    var id4118 = charIDToTypeID( "Pnt " );
    desc623.putObject( id4113, id4118, desc624 );
    var id4119 = charIDToTypeID( "Tlrn" );
    desc623.putInteger( id4119, 0 );
    executeAction( id4109, desc623, DialogModes.NO );
}