Hello everyone,
I don't have any experience in scripting really, I tried to get this to work with actions but it didn't work so well.
Basically what I want to do is, with an open image of any size, average the first single column of pixels, and then, select the next column and average those etc. until each vertical column has been averaged.
So that it ends up like this, a series of averaged columns:
It can be done by hand obviously, with the single column marquee selection tool and the average blur. But does anyone have any guide how this could be achieved with a script?
Average each pixel column individually
-
Mikaeru
Average each pixel column individually
Moseley3 wrote:Basically what I want to do is, with an open image of any size, average the first single column of pixels, and then, select the next column and average those etc. until each vertical column has been averaged.
But does anyone have any guide how this could be achieved with a script?
Please try this code snippet (to be on the safe side, it duplicates the document first, but this depends on your needs...):
Code: Select all// var doc = app.activeDocument;
var doc = app.activeDocument.duplicate ("Averaged Columns");
var width = doc.width;
var height = doc.height;
var resolution = doc.resolution;
doc.resizeImage (width, 1, resolution, ResampleMethod.NEARESTNEIGHBOR);
doc.resizeImage (width, height, resolution, ResampleMethod.NEARESTNEIGHBOR);
HTH...
--Mikaeru
But does anyone have any guide how this could be achieved with a script?
Please try this code snippet (to be on the safe side, it duplicates the document first, but this depends on your needs...):
Code: Select all// var doc = app.activeDocument;
var doc = app.activeDocument.duplicate ("Averaged Columns");
var width = doc.width;
var height = doc.height;
var resolution = doc.resolution;
doc.resizeImage (width, 1, resolution, ResampleMethod.NEARESTNEIGHBOR);
doc.resizeImage (width, height, resolution, ResampleMethod.NEARESTNEIGHBOR);
HTH...
--Mikaeru
-
Moseley3
Average each pixel column individually
Hi there, thanks for the help! However, when I try this code, on the below image:
This is the result I get:
When what I am looking for is something like this:
Maybe I have done something wrong
This is the result I get:
When what I am looking for is something like this:
Maybe I have done something wrong
-
Mikaeru
Average each pixel column individually
Moseley3 wrote:When what I am looking for is something like this:
The following code should work on the provided image:
Code: Select all// var doc = app.activeDocument;
var doc = app.activeDocument.duplicate ("Averaged Columns");
var width = doc.width;
var height = doc.height;
var resolution = doc.resolution;
var resampleMethod = ResampleMethod.BILINEAR;
doc.resizeImage (width, new UnitValue ("1 px"), resolution, resampleMethod);
doc.resizeImage (width, height, resolution, ResampleMethod.NEARESTNEIGHBOR);
Apparently, depending on the image color mode, depth, etc., you will have to play with the different possible values for resampleMethod:
ResampleMethod.BICUBIC
ResampleMethod.BICUBICSHARPER
ResampleMethod.BICUBICSMOOTHER
ResampleMethod.BILINEAR
ResampleMethod.NEARESTNEIGHBOR
ResampleMethod.NONE
Also, I forgot that the 1 pixel height had to be expressed as a UnitValue, otherwise this will not work if your rulers units preferences are not set to pixels...
UPDATE: I did a few tests in the meanwhile, and it appears that ResampleMethod.NEARESTNEIGHBOR was wrong for the downscaling part anyway; it does not perform any averaging but seems to select a one-pixel-high row located in the middle of the image...
The following code should work on the provided image:
Code: Select all// var doc = app.activeDocument;
var doc = app.activeDocument.duplicate ("Averaged Columns");
var width = doc.width;
var height = doc.height;
var resolution = doc.resolution;
var resampleMethod = ResampleMethod.BILINEAR;
doc.resizeImage (width, new UnitValue ("1 px"), resolution, resampleMethod);
doc.resizeImage (width, height, resolution, ResampleMethod.NEARESTNEIGHBOR);
Apparently, depending on the image color mode, depth, etc., you will have to play with the different possible values for resampleMethod:
ResampleMethod.BICUBIC
ResampleMethod.BICUBICSHARPER
ResampleMethod.BICUBICSMOOTHER
ResampleMethod.BILINEAR
ResampleMethod.NEARESTNEIGHBOR
ResampleMethod.NONE
Also, I forgot that the 1 pixel height had to be expressed as a UnitValue, otherwise this will not work if your rulers units preferences are not set to pixels...
UPDATE: I did a few tests in the meanwhile, and it appears that ResampleMethod.NEARESTNEIGHBOR was wrong for the downscaling part anyway; it does not perform any averaging but seems to select a one-pixel-high row located in the middle of the image...