主頁 >  其他 > 基于FCN的深度學習極化SAR影像處理

基于FCN的深度學習極化SAR影像處理

2020-10-08 22:49:52 其他

基于FCN的深度學習極化SAR影像處理

本次想要做一個關于深度學習的極化SAR影像處理系列(我們關于極化SAR影像處理現在更多的是語意分割)FCN (已完成)U-net(還在寫)、Deeplab(已完成)、Yolo(正在學習),
想做這件事的主要有如下三個原因:
一、是對剛開始一年的合肥工業大學研究生學習生活中一些基礎知識的總結,
二、在學習程序中受到了中科大等前輩的指導,讓我覺得學習程序中有人適當的幫助可以加快進度,
三、希望在CSDN大佬的幫助下能夠學到更多知識,我們往往在研究生生活中只關注自己方向、而忽視其他學習的可能性,

需要的軟體:Polsarpro(最強極化SAR影像處理軟體)我主要用他來做影像特征的提取,也可以做一些傳統的分類比如SVM(支持向量機)、Wishart監督分類、非監督分類等, PauliRGB影像
華東師大的禾欠水前輩—做過相關介紹與指導,
Polsarpro的使用

Pycharm:Python開發平臺,Python應該學會python基礎的使用以及tensorflow、cv2、matplotlib、numpy、一些機器學習的基礎知識,
標簽工具:學會如何使用labelme工具,效果如下

在這里插入圖片描述
硬體配置部分:i7處理器、英偉達P4000 GPU 、32G物理記憶體

文章參考了:中科大前輩的代碼(在這感謝科大前輩)
CreateBig先生的框架書寫
這里介紹了CNN與FCN之間的對比
《Fully Convolutional Networks for Semantic Segmentation》一文介紹了FCN的全部原理,是一篇非常經典的論文,
《改進型 DeepLab 的極化 SAR 果園分類》這篇論文清楚的告訴了我如何系統性,設計一個代碼程序的思路,

整個框架大致的操作程序,我做了一個簡易的思維導圖
在這里插入圖片描述
代碼部分:
在這里插入圖片描述

#trains 部分
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import matplotlib.image as mpimg
import numpy as np
import tensorflow as tf
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt
import cv2
from transition import convert
from numpy import random
from tensorflow.keras import optimizers
from FCN_model import MyModel
from data_procession import padding,cut_image,combination

def main():
    data1 = []
    data2 = []
    data3 = []
    img_w = 256
    img_h = 256
    Buffer_size = 100
    Batch_size =8


    path = r'特征提取處'
    for i in os.walk(r'特征提取處'):
        print(i)
    i = i[2]
    for j in range(5):  # 多少個特征自己設定
        a = mpimg.imread(path + '\\%s' % i[j])
        #a = np.array(a)

        if a.shape == (2048,2048):
            data1.append(a)
        elif a.shape == (2048,2048,3):
            data2.append(a)
        else:
            data3.append(a)
    data1 = np.array(data1)
    data2 = np.array(data2)
    data3 = np.array(data3)
    data1 = data1[:, :, :, np.newaxis]  #灰度圖擴充維度
    data1 = data1.repeat([3], axis=3)
    data3 =data3[:,:,:,0:3] #特征圖RGBA四通道,除去A通道
    data4 = np.row_stack((data1, data2))
    data4 = np.row_stack((data4, data3))
    print(data4.shape)


    #進行降維措施
    data5 = data4.reshape(5,-1)
    data5 = np.transpose(data5)

    pca = PCA(n_components=3)
    data6 = pca.fit_transform(data5)
    print(data6.shape)
    data6 = np.transpose(data6)
    print(data6.shape)
    data7 = data6.reshape(3,2048,2048,3) #重新重組成三個圖片
    a = data7[0]
    b = data7[1]
    c = data7[2]
    print(tf.reduce_max(a))
    print(tf.reduce_max(b))
    print(tf.reduce_max(c))#根據你得圖片最大的像素來得到值,進行歸一化處理.
    d = a / 257
    e = b / 248
    f = c / 229

    d = d.astype(np.float32)
    e = e.astype(np.float32)
    f = f.astype(np.float32)
    #開始進行繪圖處理進行灰度圖處理,將 2048*2048*3 --> 2048 * 2048
    map1 = cv2.cvtColor(d, cv2.COLOR_RGB2GRAY)
    map2= cv2.cvtColor(e, cv2.COLOR_RGB2GRAY)
    map3 = cv2.cvtColor(f, cv2.COLOR_RGB2GRAY)

    plt.figure('grey-scale map1',figsize=(12,12),dpi=80)
    plt.imshow(map1)
    plt.figure('grey-scale map2',figsize=(12,12),dpi=80)
    plt.imshow(map2)
    plt.figure('grey-scale map3',figsize=(12,12),dpi=80)
    plt.imshow(map2)
    plt.show()

    set = [map1,map2,map3]
    data_train = []
    for i in range(3):
        data_train.append(set[i])
    data_train = np.array(data_train) #data_train:(3,2048,2048)

    data_train = data_train.reshape(3,-1)
    data_train = np.transpose(data_train)
    data_train = data_train.reshape(2048,2048,3)  #(2048,2048,3)

    img_l = tf.io.read_file(r'label.png')
    img_l = tf.image.decode_png(img_l)
    img_l = np.array(img_l)
    l = cv2.cvtColor(img_l,cv2.COLOR_RGB2GRAY)#將標簽圖 也做成RGB灰度圖
    b = [15, 38, 53, 75, 90, 113]
    converted = convert(l,b) #生成標簽的程序
    print('converted:\n',converted.shape)


    #這一段就是資料采集、訓練集合生成的程序 可以按照個人喜好隨機分配
    print('Ground Truth(label) and dataset: ')
    count = 0
    judgement = 0
    train = []
    test = []
    label_train = []
    label_test = []
    X_height, X_width ,Channel= data_train.shape  #一次性賦予像素及通道
    print(data_train.shape)

    while count < 4000:
        if judgement % 2 == 0:
            random_width = random.randint(0, X_width - img_w -1)
            random_height = random.randint(0, X_height - img_h - 1)

        else:
            random_height = random.randint(0, X_height - img_h -1)
            random_width = random.randint(0, X_width - img_w -1)
        judgement += 1
        count += 1
        data_collect = data_train[random_height : random_height + img_h , random_width :random_width + img_w, :]
        label_collect = converted[random_height : random_height + img_h , random_width :random_width + img_w]

        if count <= 3000:
            train.append(data_collect)
            label_train.append(label_collect)
        else:
            test.append(data_collect)
            label_test.append(label_collect)

    #訓練集像素值轉換到(-1,1)之間
    train = tf.cast(train, tf.float32) * 2 -1
    test = tf.cast(test, tf.float32) * 2 -1

    label_train = np.expand_dims(label_train, axis =3)
    print(label_train.shape)
    label_test = np.expand_dims(label_test, axis =3) #4個維度分別是:圖片數量、影像高度、影像寬帶、標簽0-7
    print(label_test.shape)

    dataset_train = tf.data.Dataset.from_tensor_slices((train, label_train))
    dataset_test = tf.data.Dataset.from_tensor_slices((test, label_test))
    print(dataset_train)
    print(dataset_test)  #((256,256,3),(256,256,1)),types:(tf.float32,tf.uint8)>


    dataset_train = dataset_train.shuffle(Buffer_size).batch(Batch_size)
    dataset_train = dataset_train.prefetch(buffer_size = tf.data.experimental.AUTOTUNE)
    dataset_test = dataset_test.batch((Batch_size))

    for img,musk in dataset_train.take(1):
        plt.figure('256*256 picture and 256*256Ground Truth: ',figsize = (12,12), dpi = 80)
        plt.subplot(4, 2 ,1)
        plt.imshow(tf.keras.preprocessing.image.array_to_img(img[0]))
        plt.subplot(4, 2, 2)
        plt.imshow(tf.keras.preprocessing.image.array_to_img(musk[0]))
        plt.subplot(4, 2 ,3)
        plt.imshow(tf.keras.preprocessing.image.array_to_img(img[1]))
        plt.subplot(4, 2, 4)
        plt.imshow(tf.keras.preprocessing.image.array_to_img(musk[1]))
        plt.subplot(4, 2, 5)
        plt.imshow(tf.keras.preprocessing.image.array_to_img(img[2]))
        plt.subplot(4, 2, 6)
        plt.imshow(tf.keras.preprocessing.image.array_to_img(musk[2]))
        plt.subplot(4, 2, 7)
        plt.imshow(tf.keras.preprocessing.image.array_to_img(img[3]))
        plt.subplot(4, 2, 8)
        plt.imshow(tf.keras.preprocessing.image.array_to_img(musk[3]))
    plt.show()

    conv_net = MyModel(7)
    optimizer = optimizers.Adam(lr=1e-4)
    variables = conv_net.trainable_variables


    for epoch in range(200):

        for step, (x, y) in enumerate(dataset_train):
            with tf.GradientTape() as tape:
                # [b, 256, 256, 3] => [b, 256, 256, 7]
                logits = conv_net(x)
                # 計算總共的損失總量,然后求平均
                loss = tf.losses.sparse_categorical_crossentropy(y, logits, from_logits=True)
                loss = tf.reduce_mean(loss)

            grads = tape.gradient(loss, variables)
            optimizer.apply_gradients(zip(grads, variables))

            if step % 100 == 0:
                print(epoch, step, 'loss:', float(loss))#當前的迭代次數,當前的步驟,以及當前步驟的損失總量

        total_num = 0
        total_correct = 0
        for x, y in dataset_test:
            logits = conv_net(x)
            prob = tf.nn.softmax(logits, axis=3)
            pred = tf.argmax(prob, axis=3)
            pred = tf.cast(pred, dtype=tf.int32)
            #經過conv_net、softmax以及argmax資料形狀以及從[8,256,256,,3]-->[8,256,256,7]-->[8,256,256]

            y = tf.squeeze(y, axis=3)
            #所以這里的情況就是將y的形狀從[8,256,256,1]-->[8,256,256]
            y = tf.cast(y, dtype=tf.int32)
            correct = tf.cast(tf.equal(pred, y), dtype=tf.int32)
            correct = tf.reduce_sum(correct)

            total_num += x.shape[0]
            total_correct += int(correct)

        acc = total_correct / total_num / x.shape[1] / x.shape[2]
        print(epoch, 'acc:', acc)

    for image, mask in dataset_test.take(1):
        pred_mask = conv_net.predict(image)
        pred_mask = tf.argmax(pred_mask, axis=-1)
        pred_mask = pred_mask[..., tf.newaxis]

        num = 3
        plt.figure('256*256picture、label、pred:',figsize=(10, 10),dpi=80)
        for i in range(num):
            plt.subplot(num, 3, i * num + 1)
            plt.imshow(tf.keras.preprocessing.image.array_to_img(image[i]))
            plt.subplot(num, 3, i * num + 2)
            plt.imshow(tf.keras.preprocessing.image.array_to_img(mask[i]))
            plt.subplot(num, 3, i * num + 3)
            plt.imshow(tf.keras.preprocessing.image.array_to_img(pred_mask[i]))
        plt.show()

#前面代碼,我們將一張完整的圖片隨機取樣、打散選取4000張圖片然后進行訓練、預測,這一段代碼我們將圖片進行補全、剪切、以及最終合成一張圖片
    data_train = padding(data_train,2048)
    plt.imshow(tf.keras.preprocessing.image.array_to_img(data_train))
    plt.show()#這里可以展示一下我們所有提取出來的特征圖融合成一張圖片三通道偽彩圖的樣子

    data_train = tf.cast(data_train, tf.float32) * 2 - 1
    data_train = cut_image(data_train, 256)

    data_train = np.array(data_train)
    print('data_train.shape:\n', data_train.shape)

    data_all = tf.data.Dataset.from_tensor_slices(data_train)
    data_all = data_all.batch(Batch_size)

    s = []

    for x in data_all:
        logits = conv_net(x)
        prob = tf.nn.softmax(logits, axis =3)
        pred = tf.argmax(prob, axis =3)
        pred = tf.cast(pred, dtype = tf.int32)
        s.append(pred)
    s = np.array(s)
    s = s.reshape(64, 256, 256)
    print(s.shape)
    s = combination(s)
    s = np.array(s)
    print(s.shape)
    print(np.unique(s))

    x1 = converted
    x2 = s


    color1 = [0, 0, 0, 0, 0, 0, 0]
    color2 = [0, 0, 0, 0, 0, 0, 0]
    color3 = [0, 0, 0, 0, 0, 0, 0]
    color4 = [0, 0, 0, 0, 0, 0, 0]
    color5 = [0, 0, 0, 0, 0, 0, 0]
    color6 = [0, 0, 0, 0, 0, 0, 0]
    color7 = [0, 0, 0, 0, 0, 0, 0]

    for i in range(2048):
        for j in range(2048):
            if (x1[i][j] == x2[i][j]):
                if (x1[i][j] == 0):
                    color1[0] += 1
                elif (x1[i][j] == 1):
                    color2[1] += 1
                elif (x1[i][j] == 2):
                    color3[2] += 1
                elif (x1[i][j] == 3):
                    color4[3] += 1
                elif (x1[i][j] == 4):
                    color5[4] += 1
                elif (x1[i][j] == 5):
                    color6[5] += 1
                elif (x1[i][j] == 6):
                    color7[6] += 1
    for i in range(2048):
        for j in range(2048):
            if (x1[i][j] != x2[i][j]):
                if (x1[i][j] == 0):
                    if (x2[i][j] == 1):
                        color1[1] += 1
                    elif (x2[i][j] == 2):
                        color1[2] += 1
                    elif (x2[i][j] == 3):
                        color1[3] += 1
                    elif (x2[i][j] == 4):
                        color1[4] += 1
                    elif (x2[i][j] == 5):
                        color1[5] += 1
                    elif (x2[i][j] == 6):
                        color1[6] += 1
                if (x1[i][j] == 1):
                    if (x2[i][j] == 0):
                        color2[0] += 1
                    elif (x2[i][j] == 2):
                        color2[2] += 1
                    elif (x2[i][j] == 3):
                        color2[3] += 1
                    elif (x2[i][j] == 4):
                        color2[4] += 1
                    elif (x2[i][j] == 5):
                        color2[5] += 1
                    elif (x2[i][j] == 6):
                        color2[6] += 1
                elif (x1[i][j] == 2):
                    if (x2[i][j] == 0):
                        color3[0] += 1
                    elif (x2[i][j] == 1):
                        color3[1] += 1
                    elif (x2[i][j] == 3):
                        color3[3] += 1
                    elif (x2[i][j] == 4):
                        color3[4] += 1
                    elif (x2[i][j] == 5):
                        color3[5] += 1
                    elif (x2[i][j] == 6):
                        color3[6] += 1
                elif (x1[i][j] == 3):
                    if (x2[i][j] == 0):
                        color4[0] += 1
                    elif (x2[i][j] == 1):
                        color4[1] += 1
                    elif (x2[i][j] == 2):
                        color4[2] += 1
                    elif (x2[i][j] == 4):
                        color4[4] += 1
                    elif (x2[i][j] == 5):
                        color4[5] += 1
                    elif (x2[i][j] == 6):
                        color4[6] += 1
                elif (x1[i][j] == 4):
                    if (x2[i][j] == 0):
                        color5[0] += 1
                    elif (x2[i][j] == 1):
                        color5[1] += 1
                    elif (x2[i][j] == 2):
                        color5[2] += 1
                    elif (x2[i][j] == 3):
                        color5[3] += 1
                    elif (x2[i][j] == 5):
                        color5[5] += 1
                    elif (x2[i][j] == 6):
                        color5[6] += 1
                elif (x1[i][j] == 5):
                    if (x2[i][j] == 0):
                        color6[0] += 1
                    elif (x2[i][j] == 1):
                        color6[1] += 1
                    elif (x2[i][j] == 2):
                        color6[2] += 1
                    elif (x2[i][j] == 3):
                        color6[3] += 1
                    elif (x2[i][j] == 4):
                        color6[4] += 1
                    elif (x2[i][j] == 6):
                        color5[6] += 1
                elif (x1[i][j] == 6):
                    if (x2[i][j] == 0):
                        color7[0] += 1
                    elif (x2[i][j] == 1):
                        color7[1] += 1
                    elif (x2[i][j] == 2):
                        color7[2] += 1
                    elif (x2[i][j] == 3):
                        color7[3] += 1
                    elif (x2[i][j] == 4):
                        color7[4] += 1
                    elif (x2[i][j] == 5):
                        color7[5] += 1
    print('color1顏色的準確率:', color1[0] / np.sum(color1))
    print('color2顏色的準確率:', color2[1] / np.sum(color2))
    print('color3顏色的準確率:', color3[2] / np.sum(color3))
    print('color4顏色的準確率:', color4[3] / np.sum(color4))
    print('color5顏色的準確率:', color5[4] / np.sum(color5))
    print('color6顏色的準確率:', color6[5] / np.sum(color6))
    print('color7顏色的準確率:', color7[6] / np.sum(color7))

    s = np.expand_dims(s, axis=2)
    plt.imshow(tf.keras.preprocessing.image.array_to_img(s))
    plt.show()






if __name__ == '__main__':
    main()
#FCN_model部分
import numpy as np
import tensorflow as tf
from tensorflow.keras.layers import Conv2D, Conv2DTranspose, Add
from tensorflow.keras.layers import Dropout, Input
from tensorflow.keras.initializers import Constant


def bilinear_upsample_weights(factor, number_of_classes):
    filter_size = factor * 2 - factor % 2
    factor = (filter_size + 1) // 2
    if filter_size % 2 == 1:
        center = factor - 1
    else:
        center = factor - 0.5
    og = np.ogrid[:filter_size, :filter_size]
    upsample_kernel = (1 - abs(og[0] - center) / factor) * (1 - abs(og[1] - center) / factor)
    weights = np.zeros((filter_size, filter_size, number_of_classes, number_of_classes),
                       dtype=np.float32)
    for i in range(number_of_classes):
        weights[:, :, i, i] = upsample_kernel
    return weights


class MyModel(tf.keras.Model):
    def __init__(self, NUM_OF_CLASSESS):
        super().__init__()
        vgg16_model = self.load_vgg()
        self.conv1_1 = vgg16_model.layers[1]
        self.conv1_2 = vgg16_model.layers[2]
        self.pool1 = vgg16_model.layers[3]
        # (128,128)
        self.conv2_1 = vgg16_model.layers[4]
        self.conv2_2 = vgg16_model.layers[5]
        self.pool2 = vgg16_model.layers[6]
        # (64,64)
        self.conv3_1 = vgg16_model.layers[7]
        self.conv3_2 = vgg16_model.layers[8]
        self.conv3_3 = vgg16_model.layers[9]
        self.pool3 = vgg16_model.layers[10]
        # (32,32)
        self.conv4_1 = vgg16_model.layers[11]
        self.conv4_2 = vgg16_model.layers[12]
        self.conv4_3 = vgg16_model.layers[13]
        self.pool4 = vgg16_model.layers[14]
        # (16,16)
        self.conv5_1 = vgg16_model.layers[15]
        self.conv5_2 = vgg16_model.layers[16]
        self.conv5_3 = vgg16_model.layers[17]
        self.pool5 = vgg16_model.layers[18]
        self.conv6 = Conv2D(4096, (7, 7), (1, 1), padding="same", activation="relu")
        self.drop6 = Dropout(0.5)
        self.conv7 = Conv2D(4096, (1, 1), (1, 1), padding="same", activation="relu")
        self.drop7 = Dropout(0.5)
        self.score_fr = Conv2D(NUM_OF_CLASSESS, (1, 1), (1, 1), padding="valid", activation="relu")
        self.score_pool4 = Conv2D(NUM_OF_CLASSESS, (1, 1), (1, 1), padding="valid", activation="relu")
        self.conv_t1 = Conv2DTranspose(NUM_OF_CLASSESS, (4, 4), (2, 2), padding="same")
        self.fuse_1 = Add()
        self.conv_t2 = Conv2DTranspose(NUM_OF_CLASSESS, (4, 4), (2, 2), padding="same")
        self.score_pool3 = Conv2D(NUM_OF_CLASSESS, (1, 1), (1, 1), padding="valid", activation="relu")
        self.fuse_2 = Add()
        self.conv_t3 = Conv2DTranspose(NUM_OF_CLASSESS, (16, 16), (8, 8), padding="same", activation="sigmoid",
                                       kernel_initializer=Constant(bilinear_upsample_weights(8, NUM_OF_CLASSESS)))

    def call(self, input):
        x = self.conv1_1(input)
        x = self.conv1_2(x)
        x = self.pool1(x)
        x = self.conv2_1(x)
        x = self.conv2_2(x)
        x = self.pool2(x)
        x = self.conv3_1(x)
        x = self.conv3_2(x)
        x = self.conv3_3(x)
        x_3 = self.pool3(x)
        x = self.conv4_1(x_3)
        x = self.conv4_2(x)
        x = self.conv4_3(x)
        x_4 = self.pool4(x)
        x = self.conv5_1(x_4)
        x = self.conv5_2(x)
        x = self.conv5_3(x)
        x = self.pool5(x)
        x = self.conv6(x)
        x = self.drop6(x)
        x = self.conv7(x)
        x = self.drop7(x)
        x = self.score_fr(x)  # 第5層pool分類結果
        x_score4 = self.score_pool4(x_4)  # 第4層pool分類結果
        x_dconv1 = self.conv_t1(x)  # 第5層pool分類結果上采樣
        x = self.fuse_1([x_dconv1, x_score4])  # 第4層pool分類結果+第5層pool分類結果上采樣
        x_dconv2 = self.conv_t2(x)  # 第一次融合后上采樣
        x_score3 = self.score_pool3(x_3)  # 第三次pool分類
        x = self.fuse_2([x_dconv2, x_score3])  # 第一次融合后上采樣+第三次pool分類
        x = self.conv_t3(x)  # 上采樣
        return x

    def load_vgg(self):
        # 加載vgg16模型,其中注意input_tensor,include_top
        vgg16_model = tf.keras.applications.vgg16.VGG16(weights='imagenet', include_top=False,
                                                        input_tensor=Input(shape=(256, 256, 3)))
        for layer in vgg16_model.layers[:18]:
            layer.trainable = True
        vgg16_model.summary()
        return vgg16_model

#data_procession部分
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import numpy as np


def padding(a,target_length):#將圖片進行處理,如果原始影像就是正方形-->這一步就不做處理
    a_height, a_width, a_channel = a.shape
    if a_height < target_length:
        b = [[[0 for channel in range(a_channel)] for col in range(a_width)] for row in range(target_length - a_height)]
        a = np.concatenate((a,b), axis = 0)
    elif a_width < target_length:
        b = [[[0 for channel in range(a_channel)] for col in range(target_length - a_width)] for row in range(a_height)]
        a = np.concatenate((a, b), axis=1)

    return a


#將完整的2048*2048圖片切成256*256進行訓練
def cut_image(image,child_length):
    a_height, a_width, channels = image.shape
    data = []
    num = a_height // child_length
    for i in range(num):
        for j in range(num):
            b = image[i*child_length:(i+1)*child_length,j*child_length:(j+1)*child_length]
            data.append(b)

    c = np.array(data)
    print('剪切過后的data形狀', c.shape)
    return data

#我們之所以見資料剪切是因為,我們設定的FCN框架是[256,256,3],但是我們希望展示的是一個整圖的設計,所以我們將圖片安裝順序拼接,前面是隨機打散,但是這里是正常順序
def combination(a):
    total_num, a_height, a_width = a.shape #64,256,256
    num = np.sqrt(total_num)
    num = int(num)
    row_num = num * a_height
    col_num = num * a_width
    data = [[0 for col in range(col_num)] for row in range(row_num)]
    data = np.array(data)
    for i in range(num):
        for j in range(num):
            data[i * a_height:(i + 1) * a_height, j * a_width:(j + 1) * a_width] = a[i * num + j]
    return data

#transition部分
import  os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
import matplotlib.pyplot as plt
import cv2
import tensorflow as tf
import numpy as np

def convert(a,b):
    c = np.array(b)
    q = len(c)
    map_width,map_height = a.shape #2048,2048
    for i in range(map_width):
        for j in range(map_height):
            for k in range(q):
                if a[i][j] == b[k]:
                    a[i][j] = k+1
    return a                    #這個步驟的根本原因就在于把像素轉換成對應的標簽,由于黑色等同于 0 所以最終得到保留,比如我這里設定的是六類標簽實際 會得到7項0—6的數值

def main():
    img = tf.io.read_file(r'label.png')
    img = tf.image.decode_png(img) #解壓資料得到標簽的像素值
    img = np.array(img)

    img_label = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)
    print(np.unique(img_label))#可以到每一個標簽的像素值方便人們比較,得到數值不用取0 ,方便后續做標簽,
    plt.figure('label.shape',figsize=(15,15), dpi=80)
    plt.imshow(img_label)
    plt.show()



if __name__ == '__main__':
    main()

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/163573.html

標籤:其他

上一篇:視頻中的車牌特征識別

下一篇:如何在圖資料庫中訓練圖卷積網路模型

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more