日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

图像去雨(rainy streaks removal)#引导滤波

發布時間:2023/12/18 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 图像去雨(rainy streaks removal)#引导滤波 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文主要講述自己所作圖像去雨項目

由于雨水對光線的高反射,雨水在圖像中通常被成像為明亮的條紋,進而會影響圖像的視覺質量。攝影師可以調整曝光時間和景深這些參數來限制拍攝到雨線。然而,這種方法只能在很小程度上避免雨紋,并且不適用雨車載攝像頭使用。因此,對于大多數采集到的雨圖像來說,找到一種算法來去除圖片中的雨紋是必要的。本節將采取主成分分析法對雨條紋進行特征描述和細化處理,通過中值濾波將雨線與之鄰近的無雨背景層進行映射來恢復圖像。
本人已做項目如下,其他代碼需求也可以聯系哦!資源大把! 好了廢話不多說,開講去雨項目!

1.效果展示

雨線原圖
去雨后效果圖

2.采用方法

下圖為區域過程圖片。
雨圖可以表示為:I=B+R
I為雨圖,B為背景層,R為雨層

2.1.去雨過程

為了得到良好的去雨圖像,當務之急是要使得雨圖像的低頻背景層和高頻線特征層分離。首先,Wan發現雨滴通常對光線有很強的反射,所以它們的像素強度明顯比背景像素大,利用該理論得到了粗糙的二值圖像 M,并把高頻雨線成分視為 1 值,背景層視為 0 值。這種方法可以粗略提取出雨圖像的高頻信息,把一些無關緊要的信息進行忽略。

然而,二值圖像 M 包括了高頻細節信息和雨線信息,需要進一步的將高頻雨線與高頻細節層分離。本文采用主成分分析法,對圖像 M 中的連通區域進行分析來獲取細化的二值圖像 Mf,如圖 1?所示。所謂連通區域是指圖像中具有相同的像素值,而且彼此位置相鄰的前景像素點所構成的圖像區域。針對二值圖像 M來說,前景像素點即為圖像中白色區域,通過把每個單獨區域的特征進行分析可以進一步的優化二值圖像。

2.2 去雨重點

進行連通區域求取之前,需要確定雨線特征,對特征進行閾值劃分來達到將二值圖像 M 中的高頻雨線與高頻細節分離的效果。一般來說,雨線在圖像中的分布比較均勻且形狀大體固定。因此可以將雨線進行特征描述,具體的見圖 中的局部放大圖,本文把圖像中雨線特征描述為長為 L,寬為 W,傾斜角為 β 的紅色橢圓區域。根據長寬比、長、傾斜角的定義,進一步的遍歷 圖中各個獨立的連通區域,求取連通區域長寬比、傾斜角、長度的情況。通過得到的長、寬、傾斜角度與設定的雨線特征閾值的比較,可以判斷出連通區域是否屬于雨線部分,進而可以將其分離主要采用引導濾波和主成分分析 以及神經網絡進行雨線的去除,將無雨圖像作為目標標簽進行訓練。

2.3 雨特征提取

代碼如下

``引導濾波

```pythonimport tensorflow as tfdef diff_x(input, r):assert input.shape.ndims == 4left = input[:, :, r:2 * r + 1]middle = input[:, :, 2 * r + 1: ] - input[:, :, :-2 * r - 1]right = input[:, :, -1: ] - input[:, :, -2 * r - 1: -r - 1]output = tf.concat([left, middle, right], axis=2)return outputdef diff_y(input, r):assert input.shape.ndims == 4left = input[:, :, :, r:2 * r + 1]middle = input[:, :, :, 2 * r + 1: ] - input[:, :, :, :-2 * r - 1]right = input[:, :, :, -1: ] - input[:, :, :, -2 * r - 1: -r - 1]output = tf.concat([left, middle, right], axis=3)return outputdef box_filter(x, r):assert x.shape.ndims == 4return diff_y(tf.cumsum(diff_x(tf.cumsum(x, axis=2), r), axis=3), r)def guided_filter(x, y, r, eps=1e-8, nhwc=False):assert x.shape.ndims == 4 and y.shape.ndims == 4# data formatif nhwc:x = tf.transpose(x, [0, 3, 1, 2])y = tf.transpose(y, [0, 3, 1, 2])# shape checkx_shape = tf.shape(x)y_shape = tf.shape(y)assets = [tf.assert_equal( x_shape[0], y_shape[0]),tf.assert_equal( x_shape[2:], y_shape[2:]),tf.assert_greater(x_shape[2:], 2 * r + 1),tf.Assert(tf.logical_or(tf.equal(x_shape[1], 1),tf.equal(x_shape[1], y_shape[1])), [x_shape, y_shape])]with tf.control_dependencies(assets):x = tf.identity(x)# NN = box_filter(tf.ones((1, 1, x_shape[2], x_shape[3]), dtype=x.dtype), r)# mean_xmean_x = box_filter(x, r) / N# mean_ymean_y = box_filter(y, r) / N# cov_xycov_xy = box_filter(x * y, r) / N - mean_x * mean_y# var_xvar_x = box_filter(x * x, r) / N - mean_x * mean_x# AA = cov_xy / (var_x + eps)# bb = mean_y - A * mean_xmean_A = box_filter(A, r) / Nmean_b = box_filter(b, r) / Noutput = mean_A * x + mean_bif nhwc:output = tf.transpose(output, [0, 2, 3, 1])return output import os import re import time import numpy as np import tensorflow as tf import matplotlib.pyplot as plt from GuidedFilter import guided_filter##################### Select GPU device #################################### os.environ['CUDA_VISIBLE_DEVICES'] = "0" ############################################################################tf.reset_default_graph()##################### Network parameters ################################### num_feature = 512 # number of feature maps num_channels = 3 # number of input's channels patch_size = 64 # patch size learning_rate = 1e-3 # learning rate iterations = int(2e5) # iterations batch_size = 10 # batch size save_model_path = "./model/" # saved model's path model_name = 'model-iter' # saved model's name ############################################################################input_path = "./TrainData/input/" # the path of training data gt_path = "./TrainData/label/" # the path of training label# randomly select image patches def _parse_function(filename, label): image_string = tf.read_file(filename) image_decoded = tf.image.decode_jpeg(image_string, channels=3) rainy = tf.cast(image_decoded, tf.float32)/255.0image_string = tf.read_file(label) image_decoded = tf.image.decode_jpeg(image_string, channels=3) label = tf.cast(image_decoded, tf.float32)/255.0t = time.time()rainy = tf.random_crop(rainy, [patch_size, patch_size ,3],seed = t) # randomly select patchlabel = tf.random_crop(label, [patch_size, patch_size ,3],seed = t) return rainy, label # DerainNet def inference(images):with tf.variable_scope('DerainNet', reuse=tf.AUTO_REUSE): base = guided_filter(images,images, 15, 1, nhwc=True) # using guided filter for obtaining base layerdetail = images - base # detail layerconv1 = tf.layers.conv2d(detail, num_feature, 16, padding="valid", activation = tf.nn.relu)conv2 = tf.layers.conv2d(conv1, num_feature, 1, padding="valid", activation = tf.nn.relu)output = tf.layers.conv2d_transpose(conv2, num_channels, 8, strides = 1, padding="valid")return output, baseif __name__ == '__main__':RainName = os.listdir(input_path)for i in range(len(RainName)):RainName[i] = input_path + RainName[i]LabelName = os.listdir(gt_path) for i in range(len(LabelName)):LabelName[i] = gt_path + LabelName[i] filename_tensor = tf.convert_to_tensor(RainName, dtype=tf.string) labels_tensor = tf.convert_to_tensor(LabelName, dtype=tf.string) dataset = tf.data.Dataset.from_tensor_slices((filename_tensor, labels_tensor))dataset = dataset.map(_parse_function) dataset = dataset.prefetch(buffer_size=batch_size * 10)dataset = dataset.batch(batch_size).repeat() iterator = dataset.make_one_shot_iterator()rainy, labels = iterator.get_next() details_label = labels - guided_filter(labels, labels, 15, 1, nhwc=True)details_label = details_label[:, 4:patch_size-4, 4:patch_size-4, :] # output size 56details_output, _ = inference(rainy)loss = tf.reduce_mean(tf.square( details_label - details_output )) # MSE lossall_vars = tf.trainable_variables() g_optim = tf.train.AdamOptimizer(learning_rate).minimize(loss, var_list = all_vars) # optimizerprint("Total parameters' number: %d" %(np.sum([np.prod(v.get_shape().as_list()) for v in all_vars]))) saver = tf.train.Saver(var_list = all_vars, max_to_keep = 5)config = tf.ConfigProto()config.gpu_options.allow_growth = Trueinit = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())with tf.Session(config=config) as sess:with tf.device('/gpu:0'): sess.run(init) tf.get_default_graph().finalize() if tf.train.get_checkpoint_state(save_model_path): # load previous trained model ckpt = tf.train.latest_checkpoint(save_model_path)saver.restore(sess, ckpt) ckpt_num = re.findall(r'(\w*[0-9]+)\w*',ckpt)start_point = int(ckpt_num[-1]) + 1 print("Load success")else: # re-training when no models foundstart_point = 0 print("re-training")check_data, check_label = sess.run([rainy, labels])print("Check patch pair:") plt.subplot(1,2,1) plt.imshow(check_data[0,:,:,:])plt.title('input') plt.subplot(1,2,2) plt.imshow(check_label[0,:,:,:])plt.title('ground truth') plt.show()start = time.time() for j in range(start_point, iterations): # iterations_,Training_Loss = sess.run([g_optim,loss]) # trainingif np.mod(j+1,100) == 0 and j != 0: # save the model every 100 iterations end = time.time()print ('%d / %d iteraions, Training Loss = %.4f, runtime = %.1f s' % (j+1, iterations, Training_Loss, (end - start))) save_path_full = os.path.join(save_model_path, model_name)saver.save(sess, save_path_full, global_step = j+1, write_meta_graph=False)start = time.time() print('Training is finished.')sess.close()

同時,在真實數據集參數對比中,本文所提算法依舊擁有良好的表現,,本文所提算法結果在 PSNR 和 SSIM 參數中均高于對比算法。

歡迎被代碼困住的 被debug纏身的小伙伴交流解決,視覺相關代碼,單目測距,論文撰寫,(yolo,presacn,matlab,c++)皆可交流哦------------------------!

總結

以上是生活随笔為你收集整理的图像去雨(rainy streaks removal)#引导滤波的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。