Hi,
I'm trying to figure out why Craig Stark's PHD isn't finding the brightest star in my guide image (well it does sometimes but not always). I figured this was a good opportunity to start experimenting with PSJR.
The first bit is a simple median filter that smooths the image. When I try to modify the image with setSample I get this:
*** Error [000]: C:/PCL/src/scripts/PHD_exp.js, line 164: Image.setSample(): read-only image
so it seems images have an access mode. Do I first have to write to a temporary image and then copy it over the input image? Hmm, that doesn't seem to work either so I'm doing something quite incorrectly.
function Median3(img, outp) {
var ar = new Array(9);
var xsize = img.width;
var ysize = img.height;
for (var y=1; y<ysize-1; y++) {
for (var x=1; x<xsize-1; x++) {
ar[0] = img.sample((x-1),(y-1));
ar[1] = img.sample((x),(y-1));
ar[2] = img.sample((x+1),+(y-1));
ar[3] = img.sample((x-1),+(y));
ar[4] = img.sample((x),+(y));
ar[5] = img.sample((x+1),+(y));
ar[6] = img.sample((x-1),+(y+1));
ar[7] = img.sample((x),+(y+1));
ar[8] = img.sample((x+1),+(y+1));
ar.sort;
outp.setSample(ar[4], x, y, 1);
}
//Limg.ImageData[(xsize-1)+y*xsize]=img.ImageData[(xsize-1)+y*xsize]; // 1st & Last one in this row -- just grab from orig
//Limg.ImageData[y*xsize]=img.ImageData[y*xsize];
}
}
function main()
{
// Get access to the current active image window.
var window = ImageWindow.activeWindow;
if ( window.isNull )
throw new Error( "No active image" );
console.show();
console.writeln( "<end><cbr><br><b>" + window.currentView.fullId + "</b>" );
console.writeln( "Running PHD code." );
console.flush();
console.abortEnabled = true;
var img = window.currentView.image;
var outWindow = new ImageWindow(img.width, img.height, 1, 32, true, true, "Filtered");
var outView = outWindow.mainView;
var outImage = outWindow.mainView.image;
var c = 0;
console.writeln( "<end><cbr><br>* Channel #", c );
console.flush();
img.selectedChannel = c;
var E = new Median3( img, outImage );
console.flush();
}
main();