MAPIR Scripts
Search…
⌃K

Vignette (Flat Field) Correction

Correct the vignette of the Survey3 images
Please complete the SETUP GUIDE prior to running the below code
All lenses produce a vignette due to light taking longer to reach the image sensor pixels at the edge of the sensor. A vignette is where the pixels at the edges of the sensor are darker than they should be. The wider the lens angle of view the more pronounced/noticable the vignette is.
To create the flat field correction image a series of bright and dark field images were captured. To correct the vignette we simply divide the original image by the flat field image.
When a Survey3 camera saves a JPG image it automatically applies a vignette correction, so typically you do not need to correct JPG images captured by the Survey3 cameras for vignette.
  1. 2.
    Locate the project files to a known location path on your computer
  2. 3.
    Create empty working folders inFolder, outFolder, correctionFolder (see photo below)
  3. 4.
    Copy the 3 flat field images from the flatFields folder to the correctionFolder, making sure to choose the images that match the camera model (S3W, SWN) you're using.
  4. 5.
    Using your cursor right-click on the .bat file in the project files. Select "Edit"
  5. 6.
    This should open the .bat file for editing in your text editing or IDE of choice
Working folder structure
The contents of the .bat follow this structure:
@echo on
This line forces the command window to show when running the script
call "C:\Users\MAPIR\Anaconda3\Scripts\activate.bat"
This line points to the activate.bat file in the Anaconda3 installation folder, so that the scripts use the Python3 version with the previously installed libraries. You chose the installation folder path when you installed Anaconda3, which should not change unless you change where Anaconda3 is installed.
python "Vignette_Correction.py" "input folder path" "output folder path" "flat field correction images path"
This is the main script processing line, which we'll explain in more detail further down the page.
pause >nul
This line keeps the command window open after processing so you can see the processing log.
5. To run the script simply double-click or right-click and select Open on the .bat file.
A command window will pop up and provide feedback during the processing.
If you need to stop the processing you can press Ctrl+C and then answer the prompt with Y+Enter
The script is done processing when you see the final text Processing COMPLETE.

Main Script Processing Line Options

The main processing line is where you will make any changes prior to running the script.
Here is the processing line:
python "Vignette_Correction.py" "input folder path" "output folder path" "flat field correction images path"
The blank spaces in the .bat file are very important. Notice the spaces between each argument in the main processing line. If the code format does not match our examples it will not process correctly.
The input and output folder paths need to contain the path to your input image folder and the location you want the processed images to be output to.
We typically create two local folders named "inFolder" and "outFolder". The inFolder is where you put the images you want to process and the outFolder will contain the processed images.
The correctionFolder must contain 3 images titled:
  • Average Flat Field Correction ImageB.tif
  • Average Flat Field Correction ImageG.tif
  • Average Flat Field Correction ImageR.tif
correctionFolder structure
Here is an example of the input and output folder paths:
python "Vignette_Correction.py" "%~dp0\inFolder" "%~dp0\outFolder" "%~dp0\correctionFolder"
The images in the output folder will be saved to a subfolder named Processed_N, where N starts at 1 and counts up depending on if there are already other Processed folders located in the output folder or not. This is ideal so that you can output to the same location every time and it will not overwrite your previously processed images.
Here is an example of an entire .bat ready to be run:
@echo on
call "C:\Users\MAPIR\Anaconda3\Scripts\activate.bat"
python "Vignette_Correction.py" "%~dp0\inFolder" "%~dp0\outFolder" "%~dp0\correctionFolder"
pause >nul
When ran this script will open a command window and begin processing the images in local folder inFolder and save the processed results to local folder outFolder. The images will be corrected for vignette using the correction images in the correctionFolder.
Once you have made all the necessary changes to the .bat file you can save it to begin processing.

Running the Script

To run the script simply double-click or right-click and select Open on the .bat file.
A command window will pop up and provide feedback during the processing.
If you need to stop the processing you can press Ctrl+C and then answer the prompt with Y+Enter
The script is done processing when you see the final text Processing COMPLETE.