nef to jpg
If you have a Nikon DSLR camera and you shoot in RAW format, you’ll end up with a NEF file. You can easily convert several NEF files to JPG by running a Python script. It’s fast and works fairly well. If you want to run in a controlled Python environment, I suggest that you create a virtual environment. You can group all your imaging scripts in one virtual environment.
Here’s the code to convert NEF files to JPG.
import glob
import rawpy
import imageio
def nef2jpg():
directory = "." # set directory
pathnef = glob.glob(f"{directory}/*.nef") # list of nef files
pathNEF = glob.glob(f"{directory}/*.NEF") # list of NEF files
count = 0
number_files = len(pathnef) + len(pathNEF)
print("Total Number of Images: ", number_files)
for path in pathnef:
with rawpy.imread(path) as raw:
rgb = raw.postprocess()
imageio.imwrite(path.replace('.nef', '') + '.jpg', rgb) # convert nef to jpg
count = count + 1
print(count, '/', number_files)
for path in pathNEF:
with rawpy.imread(path) as raw:
rgb = raw.postprocess()
imageio.imwrite(path.replace('.NEF', '') + '.jpg', rgb) # convert NEF to jpg
count = count + 1
print(count, '/', number_files)
if __name__ == '__main__':
nef2jpg()
The script uses rawpy and imageio to convert files.