Hola,
[English version below]
dejamos aqui un pequeño script para fijar defectos de columna o filas, esta basado en el metodo que Juan propuso en el tutorial de deconvolucion y tambien en un script que Sander para disimular un defecto de columna. De momento es una version preliminar, nos gustaria que ademas de una columna completa o fila a corregir se pudiera coregir un rectangulo completo y ademas Carlos muy amablemente nos a propuesto que por defecto quede selecionado el valor de pixel de la columna/fila a arreglar al abrir el Dialogo y de momento eso no lo sabemos hacer :oops: Pero en fin, es una primera version que quizas puede ser de ayuda a alguien:
// Script to correct columns and row defects of an image
// Based on the script from the image processing tutorial:
// "NGC 5189 from GeminiObservatory..." by J.Conejero
// and on the script to average two columns by Sander:
// http://pixinsight.com/forum/viewtopic.php?t=748
#include <pjsr/Sizer.jsh>
#include <pjsr/FrameStyle.jsh>
#include <pjsr/TextAlign.jsh>
#include <pjsr/StdButton.jsh>
#include <pjsr/StdIcon.jsh>
#include <pjsr/UndoFlag.jsh>
#include <pjsr/ColorSpace.jsh>
#include <pjsr/UndoFlag.jsh>
console.hide();
var window = ImageWindow.activeWindow;
function FLUserData() {
this.fixColumn = true;
this.fixRow = false;
this.position = 0;
}
var userData = new FLUserData;
if ( window.isNull )
throw Error( "There is no active image window!" );
var view = window.mainView;
function FixLinesDialog() {
this.__base__ = Dialog;
this.__base__();
//
var emWidth = this.font.width( 'M' );
var labelWidth1 = this.font.width( "Maximum planet radius (px):" );
var spinWidth1 = 8*emWidth;
//
this.helpLabel = new Label( this );
this.helpLabel.frameStyle = FrameStyle_Box;
this.helpLabel.margin = 4;
this.helpLabel.wordWrapping = true;
this.helpLabel.useRichText = true;
this.helpLabel.text = "<b>FixLines Script</b> - Script to correct "+
"columns or rows defects in an image."
//
this.size_Label = new Label( this );
this.size_Label.text = "Column/Row position (px):";
this.size_Label.textAlignment = TextAlign_Right|TextAlign_VertCenter;
this.size_Label.minWidth = labelWidth1;
this.size_SpinBox = new SpinBox( this );
this.size_SpinBox.minValue = 0;
this.size_SpinBox.maxValue = Math.max(view.image.height,view.image.width);
this.size_SpinBox.value = 0 ;
this.size_SpinBox.setFixedWidth( spinWidth1 );
this.size_SpinBox.toolTip = "Column or Row position";
this.size_SpinBox.onValueUpdated = function( value )
{
userData.position = value;
};
this.size_Sizer = new HorizontalSizer;
this.size_Sizer.spacing = 4;
this.size_Sizer.add( this.size_Label );
this.size_Sizer.add( this.size_SpinBox );
this.size_Sizer.addStretch();
// Type of defect: label
this.typeOfDefectLab = new Label (this);
with (this.typeOfDefectLab) {
text = "Type of Defect:";
textAlignment = TextAlign_Right | TextAlign_VertCenter;
minWidth = labelWidth1;
}
// Type of defect: radio buttons
this.typeOfDefectCol = new RadioButton (this);
with (this.typeOfDefectCol) {
text = "Column";
checked=true;
onCheck = function(checked) {
userData.fixColumn = checked;
}
}
this.typeOfDefectRow = new RadioButton (this);
with (this.typeOfDefectRow) {
text = "Row";
onCheck = function(checked) {
userData.fixRow = checked;
}
}
// mask blur method: sizer
this.typeOfDefectSize = new HorizontalSizer (this);
with (this.typeOfDefectSize) {
spacing = 16;
add (this.typeOfDefectLab);
add (this.typeOfDefectCol);
add (this.typeOfDefectRow);
addStretch();
}
//
this.ok_Button = new PushButton( this );
this.ok_Button.text = " OK ";
this.ok_Button.onClick = function()
{
this.dialog.ok();
};
this.done_Button = new PushButton( this );
this.done_Button.text = " Done ";
this.done_Button.onClick = function()
{
this.dialog.cancel();
};
this.buttons_Sizer = new HorizontalSizer;
this.buttons_Sizer.spacing = 4;
this.buttons_Sizer.addStretch();
this.buttons_Sizer.add( this.ok_Button );
this.buttons_Sizer.add( this.done_Button );
//
this.sizer = new VerticalSizer;
this.sizer.margin = 6;
this.sizer.spacing = 6;
this.sizer.add( this.helpLabel );
this.sizer.addSpacing( 4 );
this.sizer.add( this.size_Sizer );
this.sizer.add( this.typeOfDefectSize );
this.sizer.add( this.buttons_Sizer );
this.windowTitle = "FixLines Script";
this.adjustToContents();
this.setFixedSize();
}
FixLinesDialog.prototype = new Dialog;
function FixColumn( image, col, channel )
{
image.selectedChannel = channel;
for ( var y = 0; y < image.height; ++y )
image.setSample( (image.sample( col-2, y, channel ) + image.sample( col+2, y , channel ))/2, col, y , channel );
// image.selectedRect = new Rect( col, 0, col, image.height ); Ara no...
// for ( var i = 0; i < 2; ++i )
// image.convolve( [1, 2, 3, 2, 1,
// 2, 7, 11, 7, 2,
// 3, 11, 17, 11, 3,
// 2, 7, 11, 7, 2,
// 1, 2, 3, 2, 1] );
}
function FixRow( image, row, channel)
{
for ( var x = 0; x < image.width; ++x )
image.setSample( (image.sample( x, row-2, channel ) + image.sample( x , row+2, channel ))/2, x, row, channel );
// image.selectedRect = new Rect( 0, row, image.width, row ); Ara no...
// for ( var i = 0; i < 2; ++i )
// image.convolve( [1, 2, 3, 2, 1,
// 2, 7, 11, 7, 2,
// 3, 11, 17, 11, 3,
// 2, 7, 11, 7, 2,
// 1, 2, 3, 2, 1] );
}
function fixLinesEngine(userData) {
var view = window.mainView;
if(userData.fixColumn==userData.fixRow) {
throw Error( "A column and a row can not be fixed at the same time!" );
}
with (view) {
beginProcess();
var isGray = view.image.colorSpace==ColorSpace_Gray;
if(userData.fixColumn) {
if(isGray) FixColumn(image, userData.position, 0);
else {
console.writeln("hsjsh");
FixColumn(image, userData.position, 0);
FixColumn(image, userData.position, 1);
FixColumn(image, userData.position, 2);
}
} else {
if(isGray) FixRow(image, userData.position, 0);
else {
FixRow(image, userData.position, 0);
FixRow(image, userData.position, 1);
FixRow(image, userData.position, 2);
}
}
endProcess();
}
}
function main() {
var dialog = new FixLinesDialog();
dialog.view = view;
// dialog.execute();
while ( dialog.execute() )
fixLinesEngine(userData);
}
main();
Bueno un saludo a todos
Oriol&Ivette
----------------------------------------------------------------------
This is a script for fixing column or row defects. It is based on a method proposed by Juan in the Deconvolution tutorial and also in one proposed by Sander for hiding a column defect. This is only a preliminary version, we would like to correct not only a column or a row but also a rectangle. Furthermore, Carlos has kindly suggest that the pixel value for the column/row to be fixed is selected by default when the widget is called. At this time, we dont know how to implement this option :oops:, so this is a first version. We hope this can be useful for somebody
Regards