Isolating groups of pixels
I have a transparent layer with 40 -50 blocks of color in random areas.
Is there a way of isolating each block of color and placing them on their own layer?
Thanks!
Jeff
I have a transparent layer with 40 -50 blocks of color in random areas.
Is there a way of isolating each block of color and placing them on their own layer?
Thanks!
Jeff
Could you give this a try?
// lift discontinuous content from layer onto individual layers;
// for rgb-images and cs5;
// 2012, use it at your own risk;
#target photoshop
if (app.documents.length > 0 && app.activeDocument.mode = DocumentMode.RGB) {
myDocument = app.activeDocument;
myDocument.activeChannels = [myDocument.channels[0], myDocument.channels[1], myDocument.channels[2]];
// load transarency;
// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc11 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref6 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref6.putProperty( idChnl, idfsel );
desc11.putReference( idnull, ref6 );
var idT = charIDToTypeID( "T " );
var ref7 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idTrsp = charIDToTypeID( "Trsp" );
ref7.putEnumerated( idChnl, idChnl, idTrsp );
desc11.putReference( idT, ref7 );
executeAction( idsetd, desc11, DialogModes.NO );
//
var check = true;
// set to pixels;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// set to 72ppi;
var originalResolution = app.activeDocument.resolution;
myDocument.resizeImage (undefined, undefined, 72, ResampleMethod.NONE);
//
var theMask = myDocument.channels.add();
myDocument.selection.store(theMask);
myDocument.activeChannels = [myDocument.channels[0], myDocument.channels[1], myDocument.channels[2]];
//var theMask = myDocument.channels[3];
var theLayer = myDocument.activeLayer;
myDocument.selection.load(theMask, SelectionType.REPLACE);
// use threshold to heighten non black pixels;
myDocument.quickMaskMode = true;
myDocument.activeLayer.threshold(1);
myDocument.quickMaskMode = false;
// create work path;
myDocument.selection.makeWorkPath(1);
var subPathsNumber = myDocument.pathItems[myDocument.pathItems.length-1].subPathItems.length;
// check for a high number of paths;
if (subPathsNumber > 30) {
check = confirm("warning\rthere appear to be "+subPathsNumber+" elements.\rif this number is too high noise may have caused them.\rthis may result in a crash.\rproceed?")
};
// do the operation;
if (check == true) {
var thePathInfo = collectPathInfo(myDocument, myDocument.pathItems[myDocument.pathItems.length-1]);
// create one path for every subpathitem:
for (var m = 0; m < thePathInfo.length - 1; m++) {
var theSubPath = thePathInfo
; var aPath = createPath ([theSubPath], m+"_path");
aPath.makeSelection(0, true, SelectionType.REPLACE);
// expand;
myDocument.selection.expand(6);
myDocument.selection.load(theMask, SelectionType.INTERSECT);
// layer via copy;
try {
var id14 = charIDToTypeID( "CpTL" );
executeAction( id14, undefined, DialogModes.NO );
myDocumentctiveLayer.name = theLayer.name + "_" + m
}
catch (e) {};
myDocument.pathItems[myDocument.pathItems.length-1].remove();
myDocument.activeLayer = theLayer;
};
theLayer.visible = false;
};
// reset;
app.preferences.rulerUnits = originalRulerUnits;
myDocument.resizeImage (undefined, undefined, originalResolution, ResampleMethod.NONE);
};
////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
////// function to create path from array with one array per point that holds anchor, leftdirection, etc, 2010 //////
function createPath (theArray, thePointsName) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
lineSubPathArray = new Array ();
if (theArray[theArray.length - 1].constructor != Array) {var numberOfPoints = theArray.length - 1}
else {var numberOfPoints = theArray.length};
for (var b = 0; b < numberOfPoints; b++) {
var lineArray = new Array ();
for (c = 0; c < (theArray.length); c++) {
lineArray
= new PathPointInfo; if (!theArray
[3]) {lineArray .kind = PointKind.CORNERPOINT} else {lineArray
.kind = theArray [3]}; lineArray
.anchor = theArray [0]; if (!theArray
[1]) {lineArray .leftDirection = theArray [0]} else {lineArray
.leftDirection = theArray [1]}; if (!theArray
[2]) {lineArray .rightDirection = theArray [0]} else {lineArray
.rightDirection = theArray [2]}; };
lineSubPathArray = new SubPathInfo();
lineSubPathArray.operation = ShapeOperation.SHAPEADD;
if (theArray[theArray.length - 1].constructor == Array) {lineSubPathArray.closed = true}
else {lineSubPathArray.closed = theArray[theArray.length - 1]};
lineSubPathArray.entireSubPath = lineArray;
};
var myPathItem = app.activeDocument.pathItems.add(thePointsName, lineSubPathArray);
app.preferences.rulerUnits = originalRulerUnits;
return myPathItem
};
////// function to collect path-info as text //////
function collectPathInfo (myDocument, thePath) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
var theArray = [];
for (var b = 0; b < thePath.subPathItems.length; b++) {
theArray = [];
for (var c = 0; c < thePath.subPathItems.pathPoints.length; c++) {
var pointsNumber = thePath.subPathItems.pathPoints.length;
var theAnchor = thePath.subPathItems.pathPoints
.anchor; var theLeft = thePath.subPathItems.pathPoints
.leftDirection; var theRight = thePath.subPathItems.pathPoints
.rightDirection; var theKind = thePath.subPathItems.pathPoints
.kind; theArray
= [theAnchor, theLeft, theRight, theKind]; };
var theClose = thePath.subPathItems.closed;
theArray = theArray.concat(String(theClose))
};
app.preferences.rulerUnits = originalRulerUnits;
return theArray
};
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.