I have been using the Pillow code below to convert Tiff to Jpeg, but have recently found that I can use Gdal to also convert Tiff to Jpeg. I am trying to understand what the main difference is between them and if there is a reason why I should be using one over the other? Is there a quality difference? I would prefer to use the gdal code to limit the amount of packages I need in my overarching script.
The purpose is to use the JPEG's within computer vision - tensorflow - pytorch - YOLO - etc.
Image.MAX_IMAGE_PIXELS = None for infile in os.listdir(tif_path): if infile[-3:] == "tif" or infile[-3:] == "bmp": outfile = infile[:-3] + "jpeg" im = Image.open(tif_path + '/' + infile) out = im.convert("RGB") out.save(jpeg_dst + outfile, "JPEG", quality=90)
options_list = [ '-ot Byte', '-of JPEG', '-b 1', '-scale' ] options_string = " ".join(options_list) gdal.Translate( 'save_image_path.jpg', 'image_path.tif', options=options_string )