Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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;
}
}
Copy link to clipboard
Copied
That's great, Mark. Thanks very much indeed.
P.
Copy link to clipboard
Copied
Your welcome, when I dip deeper into scripting with ID. Im sure I'll have some questions for that forum too.
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now