Range Extractor - RealWorld forums

Log-in or register.

Range Extractor

PAEz
on October 29th 2013

Range Extractor
Liked the previous script and thought Id try to make a more general one that can work on other channels.

Code
Configuration

Configuration.AddEditBox("minimum", "Minimum Value", "", 0.55);
Configuration.AddEditBox("maximum", "Maximum Value", "", 1.00000001);
Configuration.AddCheckBox("greyScale", "Render as greyscale", "", false);

var options = ["Red","Green","Blue","Alpha","Hue","Lightness","Saturation"];
Configuration.Add1ofNPicker("value", "Channel", "Choose what channel to extract from", options, 5);

var text = [
//'Ranges', // Not enough room for this line
'Red, Green, Blue and Alpha : 0 - 255',
'Hue : 0 - 360',
'Lightness and Saturation : 0 - 1'
].join('\r\n');
Configuration.AddStaticText(text);

Execution

var min = Configuration.minimum;
var max = Configuration.maximum;
var greyScale = Configuration.greyScale;
var value=['R','G','B','A','H', 'L', 'S'][Configuration.value];

var image = Document.RasterImage;
var w = image.sizeX;
var h = image.sizeY;

var cL,x,y;

for (x=0; x<w; x++){
for (y=0; y<h; y++){

cL = get(x, y, value);

if (cL>max || cL<min) {
image.setPixel(x, y, 0, 0, 0);
} else if (greyScale) {
setL(x, y, value, cL);
}

}
}

function get(x,y,what,where) {
var c;
if (!where) where = image;
if (what=='R') {
c = where.getPixelRed(x, y, 0, 0);
} else if (what=='G') {
c = where.getPixelGreen(x, y, 0, 0);
} else if (what=='B') {
c = where.getPixelBlue(x, y, 0, 0);
} else if (what=='A') {
c = where.getPixelAlpha(x, y, 0, 0);
} else if (what=='H') {
c = where.getPixelH(x, y, 0, 0);
} else if (what=='L') {
c = where.getPixelL(x, y, 0, 0);
} else if (what=='S') {
c = where.getPixelS(x, y, 0, 0);
}
return c;
}

function setL(x,y,by,how,where) {
var c;
if (!where) where = image;
if (by=='R') {
c = how/255;
} else if (by=='G') {
c = how/255;
} else if (by=='B') {
c = how/255;
} else if (by=='A') {
c = how/255;
} else if (by=='H') {
c = how/360;
} else if (by=='L') {
c = how;
} else if (by=='S') {
c = how;
}
where.setPixelHLS(x, y, 0, 0, 0, c, 0);
}

Example
Modified
https://dl.dropboxusercontent.com/u/3610419/RealWorld/Pics/GawdyChrysanthemum.jpg
Original
https://dl.dropboxusercontent.com/u/3610419/RealWorld/Pics/Chrysanthemum.jpg
Thats using the range extractor on lightnets to make more obvious highlights and fatten the black (and a few other things)...looks angry now ;-) I like it.

Page views: 1017       Posts: 1      
I wish there were...
Vista & Win 7 icons
What about ICL files?