Copy link to clipboard
Copied
Hey guys, I was reading a lot about scripting the wand or quick selection. But still didn't managed to create something that will work on my case.
I would need a script that deletes the mannequin and leave only the apparel on a clean white background. (see the pictures attached)
Copy link to clipboard
Copied
Removing that mannequin would require the JavaScript magic function that has not yet been developed.
Copy link to clipboard
Copied
Thank you @JJMack, I guess we'll have to wait for that magic function.
But in the meantime, is it possible to get closer to that magic function somehow ?
Something that makes a good selection ?
Thank you !
Copy link to clipboard
Copied
Select the t-shirt then add that selection as a layer mask very easy to do.
Copy link to clipboard
Copied
Thank you @JJJMack,
how about scriptable way to do this ?
Thank you and greetings from Germany
Copy link to clipboard
Copied
I found this c.pfaffenbichler script utile
I hope it can be useful for you too.
/// c.pfaffenbichler
// 2017, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
myDocument.selection.deselect();
// magic wand selection;
magicWandTool (10,10);
magicWandTool (myDocument.width-10,10);
magicWandTool (myDocument.width-10,myDocument.height-10);
magicWandTool (10,myDocument.height-10);
// invert selection;
myDocument.selection.invert();
// layer via copy;
var id14 = charIDToTypeID( "CpTL" );
executeAction( id14, undefined, DialogModes.NO );
var thisLayer = myDocument.activeLayer;
// hide others;
hideOthers ();
// remove potential dirt;
loadTransparency(false);
myDocument.selection.contract(10);
myDocument.selection.expand(15);
myDocument.selection.invert();
myDocument.selection.clear();
myDocument.selection.deselect();
// trim with 4px edge;
cropTo(thisLayer.bounds[0]-4, thisLayer.bounds[1]-4, thisLayer.bounds[2]+4, thisLayer.bounds[3]+4);
// reset ruler;
app.preferences.rulerUnits = originalRulerUnits;
};
////// function //////
function magicWandTool (theX, theY) {
// =======================================================
var idslct = charIDToTypeID( "slct" );
var desc12 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref5 = new ActionReference();
var idmagicWandTool = stringIDToTypeID( "magicWandTool" );
ref5.putClass( idmagicWandTool );
desc12.putReference( idnull, ref5 );
executeAction( idslct, desc12, DialogModes.NO );
// =======================================================
var idAddT = charIDToTypeID( "AddT" );
var desc4 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref2.putProperty( idChnl, idfsel );
desc4.putReference( idnull, ref2 );
var idT = charIDToTypeID( "T " );
var desc5 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idHrzn, idPxl, theX );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idVrtc, idPxl, theY );
var idPnt = charIDToTypeID( "Pnt " );
desc4.putObject( idT, idPnt, desc5 );
var idTlrn = charIDToTypeID( "Tlrn" );
desc4.putInteger( idTlrn, 100 );
var idAntA = charIDToTypeID( "AntA" );
desc4.putBoolean( idAntA, true );
executeAction( idAddT, desc4, DialogModes.NO );
};
////// hide others //////
function hideOthers () {
// hide others;
// =======================================================
var idShw = charIDToTypeID( "Shw " );
var desc2 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var list1 = new ActionList();
var ref1 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref1.putEnumerated( idLyr, idOrdn, idTrgt );
list1.putReference( ref1 );
desc2.putList( idnull, list1 );
var idTglO = charIDToTypeID( "TglO" );
desc2.putBoolean( idTglO, true );
executeAction( idShw, desc2, DialogModes.NO );
};
////// load transparency //////
function loadTransparency (theInvert) {
// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref2.putProperty( idChnl, idfsel );
desc3.putReference( idnull, ref2 );
var idT = charIDToTypeID( "T " );
var ref3 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idTrsp = charIDToTypeID( "Trsp" );
ref3.putEnumerated( idChnl, idChnl, idTrsp );
desc3.putReference( idT, ref3 );
desc3.putBoolean(charIDToTypeID("Invr"), theInvert);
executeAction( idsetd, desc3, DialogModes.NO );
};
////// crop //////
function cropTo (x1, y1, x2, y2) {
// =======================================================
var idCrop = charIDToTypeID( "Crop" );
var desc7 = new ActionDescriptor();
var idT = charIDToTypeID( "T " );
var desc8 = new ActionDescriptor();
var idTop = charIDToTypeID( "Top " );
var idPxl = charIDToTypeID( "#Pxl" );
desc8.putUnitDouble( idTop, idPxl, y1 );
var idLeft = charIDToTypeID( "Left" );
var idPxl = charIDToTypeID( "#Pxl" );
desc8.putUnitDouble( idLeft, idPxl, x1);
var idBtom = charIDToTypeID( "Btom" );
var idPxl = charIDToTypeID( "#Pxl" );
desc8.putUnitDouble( idBtom, idPxl, y2 );
var idRght = charIDToTypeID( "Rght" );
var idPxl = charIDToTypeID( "#Pxl" );
desc8.putUnitDouble( idRght, idPxl, x2 );
var idRctn = charIDToTypeID( "Rctn" );
desc7.putObject( idT, idRctn, desc8 );
var idAngl = charIDToTypeID( "Angl" );
var idAng = charIDToTypeID( "#Ang" );
desc7.putUnitDouble( idAngl, idAng, 0.000000 );
var idDlt = charIDToTypeID( "Dlt " );
desc7.putBoolean( idDlt, false );
var idcropAspectRatioModeKey = stringIDToTypeID( "cropAspectRatioModeKey" );
var idcropAspectRatioModeClass = stringIDToTypeID( "cropAspectRatioModeClass" );
var idpureAspectRatio = stringIDToTypeID( "pureAspectRatio" );
desc7.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idpureAspectRatio );
var idCnsP = charIDToTypeID( "CnsP" );
desc7.putBoolean( idCnsP, false );
executeAction( idCrop, desc7, DialogModes.NO );
};
Copy link to clipboard
Copied
The magic wands tool's magic is to week for that job. That script may delete the white background pixels and delete some mannequin pixels then crop to the layers bounds if smaler the canvas size.
The tolerance use with the magic wand tool was a quitte good. Remomoved more of the mannequin then I tough it would. However the script also removet pat ot the blie t-shirt and pats of the profile image t-shirt logo.
What is needed is a cleaner mannequin and better lighting.
Copy link to clipboard
Copied
You guys are great ! Trying to help me and so many others out here !
So you are saying that it I adjust the light and paint white the mannequins I can get better results with the script posted above ?
Thank you again for your time !
Copy link to clipboard
Copied
You would also need to adjust the script some and avoid using a logo that match the white background for it will be remove in the profile shot for the white will be contiguous with the background not isolated by the t-shirts color. The script is using the magic want toot with some tip size some tolerance in contiguous mode sampling in the four corners. Then inverting the selecting and then plays some with the selection sot the t-shirt is selected not the background.. You would need to do a better job there. You could try doing a select all turn the selection into a path then stroke the path with the quick selection tool then invert that selection. The paint should be flat and the lighting even so there are no shadows so it blends with the white background the selection tool used needs to select it along with the with background. There are several scripts posted in this forum for removing a single color background. Your exposure need to make the mannequin and background one
Copy link to clipboard
Copied
For that you need the macic function try coding it see what you come up with.