Example n.4 - Multiple Output

Top  Previous  Next

In this example  the aim is to show how generating multiple output files.

 

// retrieving number of bits/pixel

nBits:=ImgGetBitsPixel(_CurrentImage);

 

//if its grayscale

if nBits=8 then

begin

 // copying  the whole image

 BinaryImage:=ImgCopy(_CurrentImage,0,0,0,0);

 

 //thresholding using fixed thresholding

 ImgThreshold(BinaryImage,127);

 

 //saving

 NewFileName:=ExtractFilePath(_CurrentOutputFile)+'FixedThresholding\'+ExtractFileName(_CurrentOutputFile);

 ImgSaveAsTif(BinaryImage,NewFileName,0,0);

 

 //deleting

 ImgDelete(BinaryImage);

 

 // re-copying  the whole image

 BinaryImage:=ImgCopy(_CurrentImage,0,0,0,0);

 

 //thresholding using of of dynamic thresholding algos

 ImgDynamicThresholdAverage( BinaryImage, 9, 9, -1, -1 );

 

 //saving

 NewFileName:=ExtractFilePath(_CurrentOutputFile)+'DynamicThresholding\'+ExtractFileName(_CurrentOutputFile);

 ImgSaveAsTif(BinaryImage,NewFileName,0,0);

 

 //deleting

 ImgDelete(BinaryImage);

 

  end;

 

 

Looking at the above code, the first thing that we need explain is the use of another image handle called BinaryImage, in fact we generate a  copy the current image using ImgCopy; this function needs the handle of the source image (_CurrentImage, in this case) and four other parameters for specifying the rectangle area we want to copy (using four ' 0 ', we'll copy the whole source image).

It's very important to stress that every time we generate (copying, creating, opening from file, etc.) a new image different from that handled by _CurrentImage, after having processed it and, if necessary,  saved it, before closing the script we must release system resources used by the image; for this purpose we use ImgDelete. This function mustn't be used with _CurrentImage or with any handle that contains its same value: current image resources are directly manage by the run-time environment, so if we use ImgDelete, we'll generate an error!

 

In the above script, if image is grayscale, we'll have in output two files: the first one will be a monochorme version generate using fixed thresholding; the second one will be the a monochrome image generated using dynamic thresholding.

 

For saving files, we have used the specific function ImgSaveAsTif

 

We note one important detail: we needn't to save _CurrentImage, because it is automatically saved by run-time environment!