Example n.2 - Conditional Processing
Previous  Top  Next

In this example we want to show a more complex algorithm; the aim is to write in output an image that is different from that loaded in input.

//retrieving number of bits/pixel
nBitsPixel:=ImgGetBitsPixel(_CurrentImage);

fileName:=ExtractFileName(_CurrentInputFile);

//despeckling

if nBitsPixel=1 then
begin
   //monochrome image
   //it will be deleted points larger than 2 pixels and higher than 2 pixels
   ImgDespeckle(_CurrentImage, 2, 2);
   ApplicationLog(_CurrentAgent,'B&W despeckling for '+fileName);
end
else if nBitsPixel=8 then
begin
   //grayscale image
   //the second parameter, '1', fixes the number of iterations of internal algorithm
   ImgGrayDespeckle(_CurrentImage,1);
   ApplicationLog(_CurrentAgent,'Gray despeckling for '+fileName);
end
else
      //color image
      ApplicationLog('Color Image, no despeckling for ' + fileName)
;

In the preceding example we showed the meaning of _CurrentInputFile; in this example we find another important system variable: _CurrentImage; it contains the handle of the current image in the batch execution and it is automatically updated by the run-time environment at each iteration of the batch processing; we never have to modify it, but only using its value when a function or a procedure requires an image handle parameter. So, we can easily understand that passing _CurrentImage parameter to ImgGetBitsPixel, we can retrieve the number of bits per pixel in the current processed image.

Looking at the details of the script, ExtractFileName extracts the name of the file, without reporting the path of the filesystem that contains it; later, according to image color characteristics, it is applied either monochome despeckling or grayscale despeckling or no despeckling in case of color image.
It's very important to underline that using _CurrentImage every kind of elaboration it will operated on the image currently loaded in memory, that will be saved in output with all adjustments we ordered through the script.