Page 1 of 1

Creating an empty image

Posted: Wed Sep 09, 2020 11:30 am
by hlohning
At times it is useful to create an artificial image for testing purposes. You can perform this task by a small ImageLab script. The following code shows how to create and calibrate such an artificial dataset. In the sample code the calibration is done only for the wavelength (=layers of the hypercube), the calibration for the other axes can be omitted if you are satisfied with pixel coordinates.

Code: Select all

program CalibrateFromData;

const
  NLAYERS = 100;   // number of layers
  NX = 10;         // size of image
  NY = 10;         //   (NX by NY pixels)

var
  CalData        : TDoubleArray;
  spec           : TDoubleArray;
  i, j, il       : integer;

begin
CreateEmptyCube (NX,NY,NLAYERS,1,ctUvVis,'N.N.','artificial dataset');
setlength (spec, NLAYERS);    // artificial spectrum
for i:=1 to NX do
  for j:=1 to NY do
    begin                     // fill HSI with artificial spectra
    for il:=1 to NLAYERS do
      spec[il-1] := il*cos(il*0.1)*sin(i)*sin(j);
    SetSpectrum (i,j,1,1,spec);
    end;
    
SetLength (CalData, NLAYERS); // create the artificial wavelength data
for i:=1 to NLAYERS do
  CalData[i-1] := 10*i + 0.003*sqr(i);  // almost linear, with small square contribution
  
MData.CalibratefromData (dimL, 1, NLAYERS, 2, MAXCALIBPOLYORDER, CalData);
MData.RecalcCalibPieces (dimL);
end.
Please note that you need to have the Extended Edition of ImageLab in order to be able to write scripts.