栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

变化检测查用操作(Matlab、Python)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

变化检测查用操作(Matlab、Python)

融合图生成(Python版)

利用tf.math.logical_and()函数实现
给定参考变化图gt和算法生成的变化图cm生成融合图

    def confusion_map(self, target_change_map, change_map):
        """
            Compute RGB confusion map for the change map.
                True positive   - White  [1,1,1]
                True negative   - Black  [0,0,0]
                False positive  - Green  [0,1,0]
                False negative  - Red    [1,0,0]
        """
        conf_map = tf.concat(
            [
                target_change_map,
                change_map,
                tf.math.logical_and(target_change_map, change_map),
            ],
            axis=-1,
            name="confusion map",
        )
        return tf.cast(conf_map, tf.float32)
if __name__ == "__main__":
    “”“
	shape of gt or cm: [H, W, 1]
	
	”“” 
    a = confusion_map(gt, cm)
OTSU阈值分割方法(Python版)

差异图通过otsu转变化图

import tensorflow as tf
import matplotlib.pyplot as plt
from PIL import Image
def threshold_otsu(image):
    """Return threshold value based on Otsu's method. Adapted to tf from sklearn
    Parameters
    ----------
    image : (N, M) ndarray
        Grayscale input image.
    nbins : int, optional
        Number of bins used to calculate histogram. This value is ignored for
        integer arrays.
    Returns
    -------
    threshold : float
        Upper threshold value. All pixels with an intensity higher than
        this value are assumed to be foreground.
    Raises
    ------
    ValueError
         If ``image`` only contains a single grayscale value.
    References
    ----------
    .. [1] Wikipedia, https://en.wikipedia.org/wiki/Otsu's_Method
    Examples
    --------
    >>> from skimage.data import camera
    >>> image = camera()
    >>> thresh = threshold_otsu(image)
    >>> binary = image <= thresh
    Notes
    -----
    The input image must be grayscale.
    """
    if len(image.shape) > 2 and image.shape[-1] in (3, 4):
        msg = (
            "threshold_otsu is expected to work correctly only for "
            "grayscale images; image shape {0} looks like an RGB image"
        )
        warn(msg.format(image.shape))

    # Check if the image is multi-colored or not
    tf.debugging.assert_none_equal(
        tf.math.reduce_min(image),
        tf.math.reduce_max(image),
        summarize=1,
        message="expects more than one image value",
    )

    hist = tf.histogram_fixed_width(image, tf.constant([0, 255]), 256)
    hist = tf.cast(hist, tf.float32)
    bin_centers = tf.range(0.5, 256, dtype=tf.float32)

    # class probabilities for all possible thresholds
    weight1 = tf.cumsum(hist)
    weight2 = tf.cumsum(hist, reverse=True)
    # class means for all possible thresholds
    mean = tf.math.multiply(hist, bin_centers)
    mean1 = tf.math.divide(tf.cumsum(mean), weight1)
    # mean2 = (tf.cumsum((hist * bin_centers)[::-1]) / weight2[::-1])[::-1]
    mean2 = tf.math.divide(tf.cumsum(mean, reverse=True), weight2)

    # Clip ends to align class 1 and class 2 variables:
    # The last value of ``weight1``/``mean1`` should pair with zero values in
    # ``weight2``/``mean2``, which do not exist.
    tmp1 = tf.math.multiply(weight1[:-1], weight2[1:])
    tmp2 = (mean1[:-1] - mean2[1:]) ** 2
    variance12 = tf.math.multiply(tmp1, tmp2)

    idx = tf.math.argmax(variance12)
    threshold = bin_centers[:-1][idx]
    return threshold
if __name__ == "__main__":
	di = plt.imread("DI.bmp")
	di = tf.convert_to_tensor(di, dtype=float)
	di = di/255
	tmp = tf.cast(di * 255, tf.int32)
	threshold = threshold_otsu(tmp) / 255
	change_map = di >= threshold
	change_map = change_map.numpy() * 255
	img = Image.fromarray(change_map.astype("uint8"))
	img = img.convert("L")
	img.save('CM.bmp')
对图片进行缩放(Matlab版)

缩放为原来的1/4倍

a = a(1:4:end, 1:4:end, :);
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/768649.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号