exe_paths = [] if fun.isCloudMode: print("=>Cloud movement detector on") else: print("=>Cloud movement detector off") if fun.isIteration: print('---Base image iteration mode---') # 构造执行命令 input_path = sys.argv[1] output_path = sys.argv[2] if fun.isReverse: paths, names, files = fun.findAllFilesReverse( input_path, '.tif') else: paths, names, files = fun.findAllFiles(input_path, '.tif') for item in files: print(item) res = fun.generateOutputFilename(output_path, names, filetype='tif') print("Images going to output:") for item in res: print(item) for i in range(res.__len__()): if i % 2 == 0: if i == 0: exe_paths.append([files[i], files[i + 1], res[i]]) else: exe_paths.append([res[i - 1], files[i + 1], res[i]])
print("[start_y]:The y coordinate of ROI's left-top point in big image.") print("[x_range]:The range of ROI in x direction(width).") print("[y_range]:The range of ROI in y direction(height).") print("\nUsage example:") print("Tool_ResizeIMG_Batch.exe C:\\tif tif C:\\tifout 100 200 3000 4000") os.system('pause') else: img_dir = sys.argv[1] img_type = sys.argv[2] out_dir = sys.argv[3] start_x = int(sys.argv[4]) start_y = int(sys.argv[5]) x_range = int(sys.argv[6]) y_range = int(sys.argv[7]) paths, names, files = fun.findAllFiles(img_dir, img_type) # 对于tif文件,统一用gdal打开并输出为tif文件 if img_type.endswith('tif') or img_type.endswith('TIF') or img_type.endswith('TIFF') or img_type.endswith( 'tiff'): for i in range(files.__len__()): bands_data = fun.readTifImageWithWindow(files[i], start_x, start_y, x_range, y_range) fun.writeTif(bands_data, out_dir + os.path.sep + names[i][:names[i].rfind('.')] + "_cut.tif") print("cutting " + (i + 1).__str__() + "/" + files.__len__().__str__()) print('cut finished.') # 对于所有其它类型的文件,如jpg、png等,统一用OpenCV处理 else: for i in range(files.__len__()): bands_data = cv2.imread(files[i]) bands_data_roi = bands_data[start_y:start_y + y_range, start_x:start_x + x_range, :] cv2.imwrite(out_dir + os.path.sep + "band_" + (i + 1).__str__().zfill(2) + ".jpg", bands_data_roi) print("cutting " + (i + 1).__str__() + "/" + files.__len__())