©2018 by Mir Mustafizur Rahman. Proudly created with Wix.com

Image Format Conversion in python: Raw to Tiff/Jpeg - Batch Processing

November 4, 2019

"""
This program reades raw format image files and converts them into
jpeg or tiff format. This code is written to enable batch processing
Required Modules:
imageio - pip install imageio
rawpy - pip install rawpy
User inputs:
1. Input Format:
2. Output Format:
3. Input image folder:
3. Output image folder:
"""

 

import rawpy # for reading raw image into python
import imageio # for converting raw image to desired format and save to disk
import glob # for reading files with specific extension from a directory

 

""" INPUT PARAMETERS  """


# set input file directory for reading raw files  
indir = "F:/BERA/Data/CFS_UAV_Data/438_30m/"

 

# set output file directory for writing files 
outdir = "F:/BERA/Data/CFS_UAV_Data/"

 

# specify input file format
informat = "DNG"

 

# Specify output file format
outformat ="tiff"

 

""" PROCESSING"""

# read the names of all the files in the directory 
files = [f for f in glob.glob(indir + "**/*."+informat, recursive=True)]

 

# loop throught each file in the directory and process one by one
for f in files:
    # print the file name that is currently being processed
    print("Current file")
    print(f)

 

    # create output file directory+name
    name_length = len(f) # lenght of the string containg input file name and directory 


    out_file = outdir+f[(len(indir)+1):(name_length-len(informat))]+outformat # output file name+directory
    
    image = rawpy.imread(f) # read image data


    rgb = image.postprocess() #convert format


    imageio.imsave(out_file, rgb) #save file to disk

Please reload

Featured Posts

I'm busy working on my blog posts. Watch this space!

Please reload

Recent Posts
Please reload

Archive
Please reload

Search By Tags
Please reload

Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
 
This site was designed with the
.com
website builder. Create your website today.
Start Now