def resample_image(input_img,output_img,target_resolutionX,target_resolutionY,method): """ resample the input image with specific resolution and resample method :param input_img: path of input image :param output_img: path of the output image :param target_resolutionX: the X resolution of output image :param target_resolutionY: the Y resolution of output image :param method: resample method(same as gdal) : nearest,bilinear,cubic,cubicspline,lanczos,average,mode :return:True if successful, False Otherwise """ if io_function.is_file_exist(input_img) is False: return False args_list = ['gdalwarp','-r',method,'-tr',str(target_resolutionX),str(target_resolutionY),input_img,output_img] return basic.exec_command_args_list_one_file(args_list,output_img)
def convert_image_to_gray_auto(output_image, input_image): """ convert inputed image to 8bit Args: output_image:output image file path input_image: input imag file path Returns:output_image if successful, False otherwise """ if os.path.isfile(output_image) is True: basic.outputlogMessage('%s already exist,skip' % output_image) return output_image input_image_obj = RSImageclass() if input_image_obj.open(input_image) is False: return False # GDT_Unknown = 0, GDT_Byte = 1, GDT_UInt16 = 2, GDT_Int16 = 3, # GDT_UInt32 = 4, GDT_Int32 = 5, GDT_Float32 = 6, GDT_Float64 = 7, # GDT_CInt16 = 8, GDT_CInt32 = 9, GDT_CFloat32 = 10, GDT_CFloat64 = 11, #GDT_Byte if input_image_obj.GetGDALDataType() == 1: # io_function.copy_file_to_dst(input_image,output_image) output_image = input_image return output_image (max_value_list, min_value_list) = RSImage.get_image_max_min_value(input_image) if max_value_list is False or min_value_list is False: return False input_image_obj = None # CommandString = 'gdal_translate -r bilinear -ot Byte -scale ' + input_image + ' '+output_image # return basic.exec_command_string_one_file(CommandString,output_image) args_list = ['gdal_translate', '-r', 'bilinear', '-ot', 'Byte'] for band_index in range(0, len(max_value_list)): args_list.append('-b') args_list.append(str(band_index + 1)) args_list.append('-scale') args_list.append(str(min_value_list[band_index])) args_list.append(str(max_value_list[band_index])) args_list.append(str(1)) args_list.append(str(254)) args_list.append(input_image) args_list.append(output_image) return basic.exec_command_args_list_one_file(args_list, output_image)