示例#1
0
    def NodeEvaluation(self, eval_info):
        image1 = eval_info.EvaluateParameter('Image')
        kernel_size = eval_info.EvaluateProperty('Kernel Size')
        kernel_x = eval_info.EvaluateProperty('Kernel X')
        kernel_y = eval_info.EvaluateProperty('Kernel Y')
        filter_type = eval_info.EvaluateProperty('Filter Type')

        image = api.RenderImage()

        img = ArrayFromImage(image1.GetImage())
        img = img.copy(order='C')

        ctx = moderngl.create_standalone_context()

        texture = ctx.texture(img.shape[1::-1], img.shape[2], img)

        window_size = 3840 // 2, 2160 // 2
        image_processing = ImageTransformer(ctx, window_size)

        # Headless
        image_processing.render(texture)
        output_img = image_processing.write()

        image.SetAsImage(ArrayToImage(output_img).convert('RGBA'))

        self.NodeSetThumb(image.GetImage())
        return image
    def NodeEvaluation(self, eval_info):
        image1 = eval_info.EvaluateParameter('Image')
        sigma_val = eval_info.EvaluateProperty('Sigma')
        intensity_val = eval_info.EvaluateProperty('Intensity')

        # Convert the current image data to an array that scipy can use
        im = ArrayFromImage(image1.GetImage())

        # Create the image
        if im.ndim == 3:
            im_grey = np.zeros((im.shape[0], im.shape[1])).astype(float)
            im_grey = (im[..., 0] * 0.3 + im[..., 1] * 0.6 + im[..., 2] * 0.1)
            im = im_grey

        im_smooth = self.SmoothGaussian(im, sigma_val)
        sobel_x, sobel_y = self.Sobel(im_smooth)

        # Calculate the normal map
        generated_normal_map = self.ComputeNormalMap(
            sobel_x,
            sobel_y,
            intensity_val
        )

        image = api.RenderImage()
        image.SetAsImage(
            ArrayToImage(generated_normal_map).convert('RGBA')
        )
        self.NodeSetThumb(image.GetImage())
        return image
示例#3
0
    def NodeEvaluation(self, eval_info):
        image1 = eval_info.EvaluateParameter('Image')
        kernel_x = eval_info.EvaluateProperty('Kernel X')
        kernel_y = eval_info.EvaluateProperty('Kernel Y')
        filter_type = eval_info.EvaluateProperty('Filter Type')

        image = api.RenderImage()

        img = ArrayFromImage(image1.GetImage())

        if filter_type == "Box":
            output_img = cv2.boxFilter(img, -1, (kernel_x, kernel_y))
        elif filter_type == "Gaussian":

            # Both values must be odd
            if (kernel_x % 2) == 0 and (kernel_y % 2) == 0:
                kernel_y += 1
                kernel_x += 1

            output_img = cv2.GaussianBlur(img, (0, 0),
                                          sigmaX=kernel_x,
                                          sigmaY=kernel_y)

        image.SetAsImage(ArrayToImage(output_img).convert('RGBA'))

        self.NodeSetThumb(image.GetImage())
        return image
    def NodeEvaluation(self, eval_info):
        image1 = eval_info.EvaluateParameter('Image')
        saturation_val = eval_info.EvaluateProperty('Saturation')
        brightness_val = eval_info.EvaluateProperty('Brightness')
        gamma_val = eval_info.EvaluateProperty('Gamma')

        # Convert the current image data to an array
        # that we can use and greyscale it.
        im = ArrayFromImage(image1.GetImage())
        gray_scale_img = cv2.equalizeHist(cv2.cvtColor(im, cv2.COLOR_BGR2GRAY))

        generated_roughness_map = self.ComputeRoughnessMap(
            gray_scale_img, saturation_val, brightness_val, gamma_val)

        image = api.RenderImage()
        image.SetAsImage(ArrayToImage(generated_roughness_map).convert('RGBA'))
        self.NodeSetThumb(image.GetImage())
        return image
示例#5
0
    def NodeEvaluation(self, eval_info):
        # TODO: Add a circle crop option
        input_image = eval_info.EvaluateParameter('Image')

        method = eval_info.EvaluateProperty("Method")
        # Rectangle
        x = eval_info.EvaluateProperty("X")
        y = eval_info.EvaluateProperty("Y")
        width = eval_info.EvaluateProperty("Width")
        height = eval_info.EvaluateProperty("Height")
        # Circle
        center = eval_info.EvaluateProperty("Center")
        radius = eval_info.EvaluateProperty("Radius")

        input_image_array = ArrayFromImage(input_image.GetImage())
        if method == "Rectangle":
            output_image_array = input_image_array[y:y + height, x:x + width]
        else:
            # Create a blank mask
            mask = np.zeros(shape=input_image_array.data.shape, dtype=np.uint8)
            # Create the circle
            circle_mask_colour = cv2.circle(mask, tuple(center), radius,
                                            (255, 255, 255), -1)
            # Convert the mask to gray scale
            circle_mask = cv2.cvtColor(circle_mask_colour, cv2.COLOR_BGR2GRAY)
            # Combine the mask and image
            cropped_img = cv2.bitwise_and(input_image_array,
                                          input_image_array,
                                          mask=circle_mask)

            # Crop the circle
            circle_rect = cropped_img[center[1] - radius:center[1] + radius,
                                      center[0] - radius:center[0] + radius]
            output_image_array = circle_rect

        image = api.RenderImage()

        image.SetAsImage(ArrayToImage(output_image_array).convert("RGBA"))

        self.NodeSetThumb(image.GetImage().convert("RGBA"))
        return image
示例#6
0
    def NodeEvaluation(self, eval_info):
        input_image = eval_info.EvaluateParameter("Image")
        method = eval_info.EvaluateProperty("Method")
        lower_threshold = eval_info.EvaluateProperty("Lower Threshold")
        higher_threshold = eval_info.EvaluateProperty("Higher Threshold")

        image = api.RenderImage()

        # Consider removing the Pillow method?
        if method == "Find Edges":
            img = input_image.GetImage().convert("L").filter(
                ImageFilter.FIND_EDGES)
            image.SetAsImage(img.convert("RGBA"))
        elif method == "Canny":
            input_image_array = ArrayFromImage(input_image.GetImage())
            output_image_array = cv2.Canny(input_image_array, lower_threshold,
                                           higher_threshold)
            image.SetAsImage(ArrayToImage(output_image_array).convert("RGBA"))
        else:
            image.SetAsImage(input_image.GetImage())

        self.NodeSetThumb(image.GetImage())
        return image
示例#7
0
    def NodeEvaluation(self, eval_info):
        image1 = eval_info.EvaluateParameter('Image')
        kernel_shape = eval_info.EvaluateProperty('Kernel Shape')
        kernel_size = eval_info.EvaluateProperty('Kernel Size')
        operation = eval_info.EvaluateProperty('Operation')

        image = api.RenderImage()

        img = ArrayFromImage(image1.GetImage())

        if kernel_shape == "Rectangle":
            kshape = cv2.MORPH_RECT
        elif kernel_shape == "Ellipse":
            kshape = cv2.MORPH_ELLIPSE
        elif kernel_shape == "Cross":
            kshape = cv2.MORPH_CROSS

        kernel_img = cv2.getStructuringElement(kshape,
                                               (kernel_size, kernel_size))

        if operation == "Erode":
            output_img = cv2.erode(img, kernel_img, iterations=1)
        elif operation == "Dilate":
            output_img = cv2.dilate(img, kernel_img, iterations=1)
        elif operation == "Opening":
            output_img = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel_img)
        elif operation == "Closing":
            output_img = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel_img)
        elif operation == "Top Hat":
            output_img = cv2.morphologyEx(img, cv2.MORPH_TOPHAT, kernel_img)
        elif operation == "Black Hat":
            output_img = cv2.morphologyEx(img, cv2.MORPH_BLACKHAT, kernel_img)

        image.SetAsImage(ArrayToImage(output_img).convert("RGBA"))

        self.NodeSetThumb(image.GetImage())
        return image