def convert(now):
    print()
    img = input('Enter the filename for the output image: ')
    print()
    directory = img

    # To create the folder in sketches of that filename
    # And this folder will contain all images as transition to sketch

    parent_dir = f'.\\ImageToSketch\\sketches'
    path = os.path.join(parent_dir, directory)
    try:
        os.mkdir(path)
    except OSError as error:
        print(error)
    image = cv2.imread(now)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    cv2.imwrite(f"{path}\\{img}(gray).png", gray)
    inverted = 255 - gray
    cv2.imwrite(f"{path}\\{img}(inverted).png", inverted)
    blurred = cv2.GaussianBlur(inverted, (21, 21), 0)
    cv2.imwrite(f"{path}\\{img}(blured).png", blurred)
    inverted_blurred = 255 - blurred
    pencil_sketch = cv2.divide(gray, inverted_blurred, scale=256.0)
    cv2.imwrite(f"{path}\\{img}(final).png", pencil_sketch)
    print()
    print(f'You can find the image here: {path}\\{img}(final).png')
예제 #2
0
def rgb_to_sketch(pic_name):
    #img_rgb = cv2.imread(args["image"])
    img_rgb = cv2.imread(pic_name)
    #print(img_rgb.shape)
    img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)  ##转为灰度图
    ##可改变图片的尺寸,只设置h或者只设置w就会按照等比例放大或缩小;若都指定,则按照指定的大小变换
    img_gray = myutils.resize(img_gray, height=500)
    img_blur = cv2.GaussianBlur(img_gray, ksize=(21, 21), sigmaX=0,
                                sigmaY=0)  ##高斯滤波
    ##可改变scale的值来改变生成效果,scale越小,会让一些原本比较亮的区域变得更加清晰
    img_blend = cv2.divide(img_gray, img_blur, scale=225)  ##图像相除实现素描效果
    return img_blend
예제 #3
0
def Convert(sketch):
    #Read the image which will be in gray already
    img = cv2.imread('portrait.png')
    #Invert the grayscaled image
    inv_gray_image = 255 - img
    #Blurr the image
    Blurred_image = cv2.GaussianBlur(inv_gray_image, (21, 21), 0)
    #Invert the blurred image
    inv_blur = 255 - Blurred_image
    #Divide the original gray image with the inverted blurred image and put in a variable
    sketch = cv2.divide(img, inv_blur, scale=256)
    #Return the variable
    return sketch
예제 #4
0
def img_calc(img1, img2, method):
    if method == "add":
        return cv.add(img1, img2)
    elif method == "sub":
        return cv.subtract(img1, img2)
    elif method == "multi":
        return cv.multiply(img1, img2)
    elif method == "divide":
        return cv.divide(img1, img2)
    elif method == "and":
        return cv.bitwise_and(img1, img2)
    elif method == "or":
        return cv.bitwise_or(img1, img2)
    elif method == "not":
        return cv.bitwise_not(img1, img2)
    else:
        return False
def dodgeV2(image, mask):
    # inverting color with 255 - ...
    return cv2.divide(image, 255 - mask, scale=256)
예제 #6
0
def divide_demo(m1, m2):  #除法
    dst = cv.divide(m1, m2)
    cv.imshow("divide result", dst)
예제 #7
0
def divide_demo(m1, m2):  # 两张图片需要同样大
    dst = cv.divide(m1, m2)
    cv.imshow("divide_demo", dst)
예제 #8
0
import numpy as np
from cv2 import cv2 as cv

img = cv.imread('Images/Victor.png')

# Convert to gray scale
gray_image = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

# Invert the image
inv_gray_image = 255 - gray_image

# Blur the Image
Blurred_image = cv.GaussianBlur(inv_gray_image, (21, 21), 0)

# invert the blurred image
inv_blur = 255 - Blurred_image

sketch = cv.divide(gray_image, inv_blur, scale=256)

# Edge Cascade
canny = cv.Canny(img, )
imagem = cv.bitwise_not(canny)
cv.imshow('canny edges', imagem)

# Show the images
cv.imshow('Image', img)
#cv.imshow('Gray image', gray_image)
cv.imshow('Sketch', sketch)

cv.waitKey(0)
cv.destroyAllWindows()