Author Topic: Añadir un parámetro a HistogramTransformation / Add a parameter to HistogramTransformation  (Read 6104 times)

Offline David Serrano

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 503
[Sloppy english below]

Holas,

Intentaba modificar HT de forma que el usuario pudiera decirle "Oye, recorta las sombras de forma que el N% de los píxels se queden a cero". Para ello pensé en añadir un par de parámetros al proceso, y me puse a intentar implementarlo. Ahora mismo he cambiado de enfoque (voy a modificar los existentes en lugar de añadir nuevos) pero aún así me ha quedado el gusanillo de conseguir esto (que por supuesto no lo he conseguido xD).

He subido mis cambios aquí, están en formato diff unificado (hay también un par de cambios irrelevantes). Si alguien quiere incorporarlos a su copia de la PCL, tiene que situarse en el directorio IntensityTransformations y aplicar el parche con el comando "patch":


Code: [Select]
$ cd /path/to/pcl/src/modules/processes
$ cp -a IntensityTransformations IntensityTransformations.orig   ## backup
$ cd IntensityTransformations
$ patch -p1 < /path/to/HueIntensityTransformations.diff


A partir de aquí, compilar como siempre y disfrutar.

Obviamente el comportamiento del módulo es exactamente el mismo, aunque esperaba ver una propiedad llamada "cp0" en el árbol de objetos de Javascript. ¿Qué es lo que falta para que aparezca?



Hiya,

I was trying to modify HT to allow users to tell "Hey, clip the shadows so as to turn N% of the pixels to zero" to it. To achieve that, I thought about adding a couple of parameters to the process, and began implementing it. Right now I've decided to try another approach (modifying existing parameters instead of creating new ones) but I'd like to complete this anyway (since of course, I've failed at it xD).

I've uploaded my changes here, they're in unified diff format (there are a couple of irrelevant changes too). If anybody wants to incorporate them to their copy of the PCL, you have to go to the IntensityTransformations directory and apply the patch using the "patch" command:

Code: [Select]
$ cd /path/to/pcl/src/modules/processes
$ cp -a IntensityTransformations IntensityTransformations.orig   ## backup
$ cd IntensityTransformations
$ patch -p1 < /path/to/HueIntensityTransformations.diff


Now, compile as usual and enjoy.

Of course, the module behaviour is exactly the same, but I expected to see a new property called "cp0" in the Javascript object tree. What's missing to make it appear?
--
 David Serrano

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Hey David,

Glad to see your first experiments with PixInsight/PCL development :)

Your new ShadowsPctClipping parameter has several problems:

1. You have declared it as a single parameter, that is, your declaration (HistogramTransformationInstance.h #110) is:

Code: [Select]
double cp0;

This means that this is not a per-channel parameter. Compare it for example with (HistogramTransformationInstance.h #107):

Code: [Select]
double m[ 5 ];

which is the declaration that corresponds to the midtones balance parameter. There is an individual midtones balance for each supported channel (R, G, B, RGB/K, Alpha).

However, you declare your parameter as a child of a MetaTable (HistogramTransformationParameters.cpp #213):

Code: [Select]
ShadowsPctClipping::ShadowsPctClipping( MetaTable* T ) : MetaDouble( T )

with a corresponding declaration in HistogramTransformationParameters.h #141:

Code: [Select]
ShadowsPctClipping( MetaTable* );

and an instantiation of this parameter as a child of TheHistogramTransformationTableParameter (HistogramTransformationProcess.cpp #43):

Code: [Select]
new ShadowsPctClipping( TheHistogramTransformationTableParameter );

Here is part of the problem: your parameter should be either a child of TheHistogramTransformationProcess (which involves MetaProcess* instead of MetaTable*), or you should declare it as:

Code: [Select]
double cp0[ 5 ];

and manage it consequently, in case it is intended to be a per-channel parameter.

--

2. You have not provided a way for the core PixInsight application to communicate with your HueHistogramTransformation in order to read/write the new cp0 parameter. Just try the following to see how this works:

- Apply an instance of your HueHistogramTransformation to any image.
- Right click on the image and select LoadHistoryExplorer
- Click on the HueHistogramTransformation item on the History Explorer to generate a script
- You get an error because the core application is unable to lock the cp0 parameter.

You must add the following to the HistogramTransformationInstance::LockParameter member function:

Code: [Select]
if ( p == TheShadowsPctClippingParameter )
   return cp0+tableRow;


if the cp0 parameter is a per-channel parameter (and hence it is declared as double[ 5 ]), or:

Code: [Select]
if ( p == TheShadowsPctClippingParameter )
   return &cp0;


if it is a single parameter. In this way the core application will be able to read and write your parameter. This is indispensable for every public parameter of any process in PixInsight.

--

As a side note, if you declare a parameter as a child of a table, that is, when a parameter is a table column, it doesn't appear on the property tree of Script Editor. This is because table parameters are aggregate objects that "hide" the names of their column (or child) parameters. However, you can see the names of all table columns as comments on automatically generated scripts. For example:

Code: [Select]
var p = new CurvesTransformation;
with ( p )
{
   R = // x, y
   [
   [0.00000, 0.00000],
   [1.00000, 1.00000]];
   Rt = AkimaSubsplines;
   // ...


In the above script, the x and y parameters are columns of R, which is a MetaTable (you can verify this in the source code of CurvesTransformation). You cannot see x and y on the JavaScript property tree, however, they are there :)

Hope this clarifies a little. Very good try anyway - looking forward to see it working!

P.S.: I think anybody with sufficient programming knowledge as to understand this stuff should be able also to read this in English, so I'll save the (huge!) effort of translating it into Spanish... do you agree?
Juan Conejero
PixInsight Development Team
http://pixinsight.com/