在单层图像中检测和提取图片

时间:2014-10-07 18:22:44

标签: photoshop photoshop-script photoshop-cs5

我有一张图片,其中包括一些纯白色背景上的图片(不同大小的图片),所有图片均为1层。

我可以用photoshop隔离/提取所有图片吗?

提前谢谢你,

1 个答案:

答案 0 :(得分:0)

是和否。计算每个单独图像的位置将非常困难(并且可能涉及扫描每个像素的缓慢复杂过程)

但有一种解决方法!在没有看到这些图像的样子的情况下,我们假设

  • 整体图片都是一层。
  • 单个图像为矩形
  • 单个图像边框上不包含任何白色

使用它可以在左上方选择魔杖,反转选择并剪切图像。

//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 );
}
相关问题