Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

JS/PS CS3: identify single pixels sticking out

Community Expert ,
Jan 28, 2010 Jan 28, 2010

In a bitmap, is it possible to identify single pixels sticking out from a shape? Let's say I have this black shape in a black-and-white bitmap:

   xxxxxxxx

   xxxxxxxx

   xxxxxxxx

   xxxxxxxx

        x

an 8 by 4 rectangle with one pixel sticking out from the bottom. Question is, can I find such pixels using a script (JS) and make it white?

Thanks,

Peter

TOPICS
Actions and scripting
5.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Guru ,
Feb 01, 2010 Feb 01, 2010

Peter, I added the work around to the script. It appears to fix the problem. With my basic test files.

#target photoshop

app.bringToFront();

while (app.documents.length) {

  app.activeDocument.close(SaveOptions.PROMPTTOSAVECHANGES);

}

var defaultFolder = new Folder ('~/Desktop');

var inputFolder = defaultFolder.selectDlg('Please select your Folder of Bitmap files…');

var outputFolder = defaultFolder.selectDlg('Please Make/Select a Folder to save Cleaned up files to…');

if (inputFolder != null && outputFolder != null) {

var fileList = inputFolder.getFiles(fileFiltering);

if (fileList.length > 0) {

main(fileList);

} else {

alert('This Folder contained NO Photoshop Tiff files!');

}

} else {

alert('A Required folder was NOT chosen!!!');

}

// Main Photoshop file processing

function main(fileObjs) {

with (app) {

var whiteRef = new SolidColor();

whiteRef.rgb.red = 255;

whiteRef.rgb.green = 255;

whiteRef.rgb.blue = 255;

backgroundColor = whiteRef; // This will be used with resizeCanvas(+)

var userDisplayDialogs = displayDialogs;

var userRulerUnits = preferences.rulerUnits;

displayDialogs = DialogModes.NO;

preferences.rulerUnits = Units.PIXELS;

for (var i = 0; i < fileObjs.length; i++) {

if (fileList instanceof File) {

open(fileObjs);

var docRef = activeDocument;

with (docRef) {

var baseName = app.activeDocument.name.slice(0, -4);

if (mode != DocumentMode.GRAYSCALE) changeMode(ChangeMode.GRAYSCALE);

docRes = resolution;

resizeCanvas(width + 4, height + 4, AnchorPosition.MIDDLECENTER);

// Cleans single pixels

artLayers[0].applyMaximum(1); // Adjust as required

artLayers[0].applyMinimum(1); // Ditto

artLayers[0].invert();

artLayers[0].applyMaximum(1); // Ditto

artLayers[0].applyMinimum(1); // Ditto

artLayers[0].invert();

resizeCanvas(width - 4, height - 4, AnchorPosition.MIDDLECENTER);

var thisBitmap = bitmapOptions(docRes)

changeMode(ChangeMode.BITMAP, thisBitmap);

var newFilePath = new File(outputFolder + '/' + baseName + '.tif');

        SaveFileasTIFF(newFilePath, false, TIFFEncoding.TIFFLZW, false, false, false);

        close(SaveOptions.DONOTSAVECHANGES);

}

}

}

displayDialogs = userDisplayDialogs;

preferences.rulerUnits = userRulerUnits;

}

}

function bitmapOptions(res) {

  bitOptions = new BitmapConversionOptions();

//bitOptions.angle = 0;

//bitOptions.frequency = 150;

bitOptions.method = BitmapConversionType.HALFTHRESHOLD;

//bitOptions.pattenName = '';

bitOptions.resolution = res;

bitOptions.shape = BitmapHalfToneType.SQUARE;

return bitOptions;

}

function SaveFileasTIFF(saveFile, aC, iC, la, sC, tr) {

  tiffSaveOptions = new TiffSaveOptions();

  tiffSaveOptions.alphaChannels = aC;

  tiffSaveOptions.byteOrder = ByteOrder.MACOS;

  tiffSaveOptions.embedColorProfile = true;

  tiffSaveOptions.imageCompression = iC;

  tiffSaveOptions.layers = la;

  tiffSaveOptions.spotColors = sC;

  tiffSaveOptions.transparency = tr;

  activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);

}

// Mac ONLY filtering (Photoshop Tiff's)

function fileFiltering(fileObj) {

if (fileObj.creator == '8BIM' && fileObj.type == 'TIFF') {

return true;

} else {

return false;

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2010 Feb 01, 2010

That's great, Mark. Thanks very much indeed.

P.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 01, 2010 Feb 01, 2010
LATEST

Your welcome, when I dip deeper into scripting with ID. Im sure I'll have some questions for that forum too.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 29, 2010 Jan 29, 2010

This may sound like a stupid question, but will this always be black and white for the colors?

Also, from your example, if you look at the large vertical section there is one stray black pixel on the right side. There are also 2 stray white pixels in the upper left and lower right corners. Are you looking to take care of those also? I guess I'm just wondering exactly what would make a pixel stray or not stray.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines