Example n.2 - Conditional Processing |
Top Previous Next |
In this example we want to show a more complex algorithm; the aim is to write in output an image processed in specific way based on bits per pixel of input image.
// retrieving number of bits/pixel nBitsPixel:=ImgGetBitsPixel(_CurrentImage);
// extracting file name from full path fileName:=ExtractFileName(_CurrentInputFile);
// conditional despeckling
if nBitsPixel=1 then begin //monochrome image ApplicationLog('B&W despeckling for '+fileName); //it will be deleted points smaller than 2x2 pixels ImgDespeckle(_CurrentImage, 2, 2); end else if nBitsPixel=8 then begin //grayscale image ApplicationLog('Gray despeckling for '+fileName); //the second parameter, '1', fixes the number of iterations of internal algorithm ImgGrayDespeckle(_CurrentImage,1); end else begin //color image ApplicationLog('Color Image, no despeckling for ' + fileName); end;
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. |