예제 #1
0
def transfertColor(src, ref, output,gamma):
    img_src = read(src)
    tonemap = reinhard(img_src)
    write("in1.jpg",tonemap)
    img_src = adjust_gamma(img_src,gamma)
    img_src = BGRtoLalphabeta(img_src)

    img_ref = read(ref)
    tonemap = reinhard(img_ref)
    write("in2.jpg",tonemap)
    img_ref = adjust_gamma(img_ref,gamma)
    img_ref = BGRtoLalphabeta(img_ref)

    mean_src, stddev_src = cv2.meanStdDev(img_src)
    mean_ref, stddev_ref = cv2.meanStdDev(img_ref)

    split_src = cv2.split(img_src)
    img_out = cv2.merge((computeColor(split_src[0], mean_src[0], stddev_src[0], mean_ref[0], stddev_ref[0]),
                         computeColor(split_src[1], mean_src[1], stddev_src[1], mean_ref[1], stddev_ref[1]),
                         computeColor(split_src[2], mean_src[2], stddev_src[2], mean_ref[2], stddev_ref[2])))
    img_out = LalphabetatoBGR(img_out)
    img_out = adjust_gamma(img_out,1./gamma)

    write(output, img_out)
    tonemap = logarithme(img_out)
    write("out.jpg",tonemap)
예제 #2
0
def colorTransfer(src: str, ref: str, output: str, gamma: float):
    img_src = cv2.imread(src, cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH)
    tonemap = reinhard(img_src)
    cv2.imwrite("in1.jpg", tonemap)
    img_src = adjust_gamma(img_src, gamma)
    img_src = BGRtoLab(img_src)

    img_ref = cv2.imread(ref, cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH)
    tonemap = reinhard(img_ref)
    cv2.imwrite("in2.jpg", tonemap)
    img_ref = adjust_gamma(img_ref, gamma)
    img_ref = BGRtoLab(img_ref)

    mean_src, stddev_src = cv2.meanStdDev(img_src)
    mean_ref, stddev_ref = cv2.meanStdDev(img_ref)

    split_src = cv2.split(img_src)
    img_out = cv2.merge((computeColor(split_src[0], mean_src[0], stddev_src[0],
                                      mean_ref[0], stddev_ref[0]),
                         computeColor(split_src[1], mean_src[1], stddev_src[1],
                                      mean_ref[1], stddev_ref[1]),
                         computeColor(split_src[2], mean_src[2], stddev_src[2],
                                      mean_ref[2], stddev_ref[2])))
    img_out = LabtoRGB(img_out)
    img_out = adjust_gamma(img_out, 1. / gamma)

    cv2.imwrite(output, img_out)
    tonemap = logarithme(img_out)
    cv2.imwrite("out.jpg", tonemap)
예제 #3
0
def color_filter(img):
    hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)
    result = cv.meanStdDev(hsv)
    print(result[1][2])
    lower_white = np.array([0, 0, int(result[1][2]) + 100])
    upper_white = np.array([255, 255, 255])
    masked_white = cv.inRange(hsv, lower_white, upper_white)
    return masked_white
예제 #4
0
def others_demo(image):
    mean = cv.mean(image)  #cv.mean():均值
    meanStdDev = cv.meanStdDev(
        image)  #cv.meanStdDev():方差,返回2darray,【1】是均值,【2】是方差
    #dst1 = cv.subtract(image,mean)
    print("mean:")
    print(mean)
    print("meanStdDev:")
    print(meanStdDev)
예제 #5
0
def grey_filter(grey_frame):
    result = cv.meanStdDev(grey_frame)
    lower = np.array(int(result[0][0]) + int(result[1][0]))
    upper = np.array(255 - int(result[1][0]))
    masked = cv.inRange(grey_frame, lower, upper)
    # cv.putText(masked, str(result[0][0]), (10, 50),
    #            cv.FONT_HERSHEY_SIMPLEX, 1, (100, 100, 100), 2, cv.LINE_AA)
    # cv.putText(masked, str(result[1][0]), (10, 100),
    #            cv.FONT_HERSHEY_SIMPLEX, 1, (100, 100, 100), 2, cv.LINE_AA)
    return masked
예제 #6
0
def color_filter(img):
    hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)
    result = cv.meanStdDev(hsv)
    lower_white = np.array([0, 0, int(result[1][2]) + int(result[0][2])])
    upper_white = np.array([255, 255, 255])
    masked_white = cv.inRange(hsv, lower_white, upper_white)
    cv.putText(masked_white, str(result[0][2]), (10, 50),
               cv.FONT_HERSHEY_SIMPLEX, 1, (100, 100, 100), 2, cv.LINE_AA)
    cv.putText(masked_white, str(result[1][2]), (10, 100),
               cv.FONT_HERSHEY_SIMPLEX, 1, (100, 100, 100), 2, cv.LINE_AA)
    return masked_white
예제 #7
0
def transfertColor(src, ref, output,gamma):
    img_src = read(src)
    img_src = adjust_gamma(img_src,gamma)
    img_src = BGRtoLalphabeta(img_src)

    img_ref = cv2.imread(ref)
    img_ref = adjust_gamma(img_ref,gamma)
    img_ref = BGRtoLalphabeta(img_ref)

    mean_src, stddev_src = cv2.meanStdDev(img_src)
    mean_ref, stddev_ref = cv2.meanStdDev(img_ref)
    split_src = cv2.split(img_src)
    img_out = cv2.merge((computeColor(split_src[0], mean_src[0], stddev_src[0], mean_ref[0], stddev_ref[0]),
                         computeColor(split_src[1], mean_src[1], stddev_src[1], mean_ref[1], stddev_ref[1]),
                         computeColor(split_src[2], mean_src[2], stddev_src[2], mean_ref[2], stddev_ref[2])))

    img_out = LalphabetatoBGR(img_out)
    img_out = FloatToUint8(img_out)
    img_out = adjust_gamma(img_out,1./gamma)

    write(output, img_out)
예제 #8
0
def colorTransfer(src: str, ref: str, output: str, gamma: float = 1.0):
    img_src = cv2.imread(src)
    img_ref = cv2.imread(ref)

    img_src = BGRtoLab(img_src)
    img_ref = BGRtoLab(img_ref)

    mean_src, stddev_src = cv2.meanStdDev(img_src)
    mean_ref, stddev_ref = cv2.meanStdDev(img_ref)
    split_src = cv2.split(img_src)
    img_out = cv2.merge((computeColor(split_src[0], mean_src[0], stddev_src[0],
                                      mean_ref[0], stddev_ref[0]),
                         computeColor(split_src[1], mean_src[1], stddev_src[1],
                                      mean_ref[1], stddev_ref[1]),
                         computeColor(split_src[2], mean_src[2], stddev_src[2],
                                      mean_ref[2], stddev_ref[2])))

    img_out = LabtoRGB(img_out)
    img_out = FloatToUint8(img_out)

    cv2.imwrite(output, img_out)
def transfert(src, ref, gamma=1.0):
    img_src = src
    #img_src = adjust_gamma(src,gamma)
    #img_src = BGRtoLalphabeta(img_src)

    img_ref = ref
    #img_ref = adjust_gamma(ref,gamma)
    #img_ref = BGRtoLalphabeta(img_ref)

    mean_src, stddev_src = cv2.meanStdDev(img_src)
    mean_ref, stddev_ref = cv2.meanStdDev(img_ref)
    split_src = cv2.split(img_src)
    img_out = cv2.merge((computeColor(split_src[0], mean_src[0], stddev_src[0],
                                      mean_ref[0], stddev_ref[0]),
                         computeColor(split_src[1], mean_src[1], stddev_src[1],
                                      mean_ref[1], stddev_ref[1]),
                         computeColor(split_src[2], mean_src[2], stddev_src[2],
                                      mean_ref[2], stddev_ref[2])))

    #img_out = LalphabetatoBGR(img_out)
    img_out = FloatToUint8(img_out)

    return img_out
def preprocess(img, imgSize, dataAugmentation=False):
    "put img into target img of size imgSize, transpose for TF and normalize gray-values"

    # there are damaged files in IAM dataset - just use black image instead
    if img is None:
        img = np.zeros([imgSize[1], imgSize[0]])

    # increase dataset size by applying random stretches to the images
    if dataAugmentation:
        stretch = (random.random() - 0.5)  # -0.5 .. +0.5
        wStretched = max(int(img.shape[1] * (1 + stretch)),
                         1)  # random width, but at least 1
        img = cv2.resize(
            img, (wStretched,
                  img.shape[0]))  # stretch horizontally by factor 0.5 .. 1.5

    # create target image and copy sample image into it
    (wt, ht) = imgSize
    (h, w) = img.shape
    fx = w / wt
    fy = h / ht
    f = max(fx, fy)
    newSize = (max(min(wt, int(w / f)), 1), max(
        min(ht, int(h / f)),
        1))  # scale according to f (result at least 1 and at most wt or ht)
    img = cv2.resize(img, newSize)
    target = np.ones([ht, wt]) * 255
    target[0:newSize[1], 0:newSize[0]] = img

    # transpose for TF
    img = cv2.transpose(target)

    # normalize
    (m, s) = cv2.meanStdDev(img)
    m = m[0][0]
    s = s[0][0]
    img = img - m
    img = img / s if s > 0 else img
    return img
예제 #11
0
# coding : utf-8
from cv2 import cv2
import numpy as np

img = cv2.imread(r'pictures\cat.jpg', cv2.IMREAD_GRAYSCALE)
cv2.namedWindow("input", cv2.WINDOW_AUTOSIZE)
cv2.imshow("input", img)

min, max, minLoc, maxLoc = cv2.minMaxLoc(img)
print("min: %.2f, max: %.2f" % (min, max))
print("min loc: ", minLoc)
print("max loc: ", maxLoc)

means, stddev = cv2.meanStdDev(img)  # means:均值, stddev:标准差
print("mean: %.2f, stddev: %.2f" % (means, stddev))
img[np.where(img < means)] = 0
img[np.where(img > means)] = 255
cv2.imshow("binary", img)  # 图片二值化,大于均值为255,小于均值为0.

cv2.waitKey(0)
cv2.destroyAllWindows()
예제 #12
0
        dist = distMap(frame1, frame3)
    except:
        print('Camera not found.')
        exit(0)
    frame1 = frame2
    frame2 = frame3
    keyPress = cv2.waitKey(20)

    # Apply Gaussian smoothing.
    mod = cv2.GaussianBlur(dist, (9, 9), 0)

    # Apply thresholding.
    _, thresh = cv2.threshold(mod, 100, 255, 0)

    # Calculate st dev test.
    _, stDev = cv2.meanStdDev(mod)

    # If motion is dectected.
    if stDev > sdThresh:
        
        # Motion is detected.
        cv2.putText(frame2, 'MD-Frame '+str(img_index),
                    (0, 20), font, 0.8, (0, 255, 0), 2, cv2.LINE_AA)
        

        # Save a timestamped jpg if motion detected.
        if motion_detect == 1:
            frame_name = (str(img_index)+str('.jpg'))
            cv2.imwrite(frame_name, frame2)
            img_index += 1
예제 #13
0
 def get_mean_std_temperature(self, thermal_image):
     plt.imshow(self.region_mask)
     plt.show()
     mean, std = cv2.meanStdDev(thermal_image, mask=self.region_mask)
     return mean.item(), std.item()