Skip to main content
Known Participant
August 1, 2023
Answered

Hi all . . .

  • August 1, 2023
  • 3 replies
  • 1815 views

What if we set the pixel ratio? For example, 1000x1000 pixel is Blur 3 radius pixels. 2000x2000 pixel is blur 6 radius pixels. If it's 1500x1500 pixels, can you make scripts to add how much blur radius... Before clicking the scripts, I'll set the selection with rectangular marquee tools and how many pixels to set.

This topic has been closed for replies.
Correct answer c.pfaffenbichler

Hello Sir @c.pfaffenbichler  

I tried to fix the scripts for Unsharp Mask but I don't know where I'm going wrong, the usharp mask scripts are unusable, please help me

 

// 2024, use it at your own risk;
if (app.documents.length > 0) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
if (hasSelection() == true) {
var theBounds = activeDocument.selection.bounds;
var theWidth = theBounds[2] - theBounds[0];
var theHeight = theBounds[3] - theBounds[1];
var theValue = Math.max(theWidth, theHeight) * 0.021;
UnsharpMask (theValue)
};
app.preferences.rulerUnits = originalRulerUnits;
};
////// UnsharpMask //////
function UnsharpMask (theAmount, theRadius, theThreshold) {
try {
var desc1 = new ActionDescriptor();
desc1.putUnitDouble( charIDToTypeID( "Amnt " ), charIDToTypeID( "#Prc" ), theAmount );
desc1.putUnitDouble( charIDToTypeID( "Rds " ), charIDToTypeID( "#Pxl" ), theRadius );
desc1.putInteger( charIDToTypeID( "Thsh" ), theThreshold );
executeAction( stringIDToTypeID( "UnsharpMask" ), desc1, DialogModes.NO );
app.refresh();
} catch (e) {}
};
////// check for selection //////
function hasSelection(){
var ref10 = new ActionReference();
ref10.putProperty(stringIDToTypeID("property"), stringIDToTypeID("selection"));
ref10.putEnumerated( charIDToTypeID( "Dcmn" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
var docDesc = executeActionGet(ref10);
return docDesc.hasKey(stringIDToTypeID("selection"));
};


For one thing a function that takes three arguments should be fed three arguments. 

// 2024, use it at your own risk;
if (app.documents.length > 0) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
if (hasSelection() == true) {
var theBounds = activeDocument.selection.bounds;
var theWidth = theBounds[2] - theBounds[0];
var theHeight = theBounds[3] - theBounds[1];
var theValue = Math.max(theWidth, theHeight) * 0.021;
unsharpMask (120, theValue, 10)
};
app.preferences.rulerUnits = originalRulerUnits;
};
////// unsharp mask //////
function unsharpMask (amount, radius, threshold) {
var desc2 = new ActionDescriptor();
desc2.putUnitDouble( idAmnt = charIDToTypeID( "Amnt" ), charIDToTypeID( "#Prc" ), amount );
desc2.putUnitDouble( charIDToTypeID( "Rds " ), charIDToTypeID( "#Pxl" ), radius );
desc2.putInteger( charIDToTypeID( "Thsh" ), threshold );
executeAction( charIDToTypeID( "UnsM" ), desc2, DialogModes.NO);
};
////// check for selection //////
function hasSelection(){
var ref10 = new ActionReference();
ref10.putProperty(stringIDToTypeID("property"), stringIDToTypeID("selection"));
ref10.putEnumerated( charIDToTypeID( "Dcmn" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
var docDesc = executeActionGet(ref10);
return docDesc.hasKey(stringIDToTypeID("selection"));
};

 

3 replies

Stephen Marsh
Community Expert
Community Expert
August 1, 2023

@Thiha31203570tbl0 – Is this related to your similar post below?

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/frequency-separation-action/m-p/13977484

 

If performing frequency separation, it is normally done on the entire canvas, not a selection. It can always be masked afterwards.

Known Participant
August 1, 2023

@23479758 Marsh ... Yes bro ... I want to Creat Skin smoothness automatically Action

 

Stephen Marsh
Community Expert
Community Expert
August 2, 2023

There are no magic numbers, although resolution plays a part, it is all about the level of detail that is required in the HF layer vs. the LF layer.

c.pfaffenbichler
Community Expert
Community Expert
August 1, 2023

You can use the bounds of the active Selection to determine its width and height and then calculate the Filter-value. 

But what about non-square Selections? How exactly should those influence the target-value? 

c.pfaffenbichler
Community Expert
Community Expert
August 1, 2023

 

// 2023, use it at your own risk;
if (app.documents.length > 0) {
    var originalRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    if (hasSelection() == true) {
        var theBounds = activeDocument.selection.bounds;
        var theWidth = theBounds[2] - theBounds[0];
        var theHeight = theBounds[3] - theBounds[1];
        var theValue = Math.max(theWidth, theHeight) * 0.003;
        gaussianBlur (theValue)
    };
    app.preferences.rulerUnits = originalRulerUnits;
};
////// gaussian blur //////
function gaussianBlur (value) {
try {
var idGsnB = charIDToTypeID( "GsnB" );
var desc4 = new ActionDescriptor();
var idRds = charIDToTypeID( "Rds " );
var idPxl = charIDToTypeID( "#Pxl" );
desc4.putUnitDouble( idRds, idPxl, value );
executeAction( idGsnB, desc4, DialogModes.NO );
app.refresh();
} catch (e) {}
};
////// check for selection //////
function hasSelection(){
var ref10 = new ActionReference();
ref10.putProperty(stringIDToTypeID("property"), stringIDToTypeID("selection"));
ref10.putEnumerated( charIDToTypeID( "Dcmn" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
var docDesc = executeActionGet(ref10);
return docDesc.hasKey(stringIDToTypeID("selection"));
};

 

Known Participant
August 2, 2023

If I want to replace Gaussian Blur with Highpass, how can I fix it in the scripts?

Bojan Živković11378569
Community Expert
Community Expert
August 1, 2023

Are you looking for help with scripting? I will tag few experts who can help you @c.pfaffenbichler @Stephen Marsh