From 46c8a4fdba1189d3dcb4b15cdb6c143d4e558fcd Mon Sep 17 00:00:00 2001 From: Nourepide Date: Tue, 13 Jun 2023 09:23:06 +0300 Subject: [PATCH] Update ImageFilter module and README.MD --- README.MD | 45 +++++++++-- modules/ImageFilter.py | 176 +++++++++++++++++++++++++---------------- 2 files changed, 147 insertions(+), 74 deletions(-) diff --git a/README.MD b/README.MD index 7cd00e9..7c71dee 100644 --- a/README.MD +++ b/README.MD @@ -592,6 +592,13 @@ You also can change the fonts folder in config. ### Blur ![image_filter_blur](images/image_filter_blur.png) > Blurring the image. + +
+ Params: + +* size_[x, y] `[1 - *]` - The strength of the blur application for horizontal and vertical direction. + +
### Box Blur ![image_filter_box_blur](images/image_filter_box_blur.png) @@ -600,7 +607,7 @@ You also can change the fonts folder in config.
Params: -* radius `[0 - *]` - blurring radius. +* size_[x, y] `[1 - *]` - The strength of the blur application for horizontal and vertical direction.
@@ -611,18 +618,44 @@ You also can change the fonts folder in config.
Params: -* radius `[0 - *]` - blurring radius. +#### All +* size_[x, y] `[1 - *]` - The strength of the blur application for horizontal and vertical direction. + +#### Advanced +* sigma_[x, y] `[1 - *]` - The scale of the blur deviation.
-### Median Blur -![image_filter_median](images/image_filter_median.png) -> Selects the average pixel value in a window of the specified size. +### Stack Blur +![image_filter_stack_blur](images/image_filter_stack_blur.png) +> Blurring the image by stack algorithm.
Params: -* size `[0 - *]` - The size of the core in PX. +* size_[x, y] `[1 - *]` - The strength of the blur application for horizontal and vertical direction. + +
+ +### Median Blur +![image_filter_median_blur](images/image_filter_median_blur.png) +> Blurring the image by median algorithm. + +
+ Params: + +* size_[x, y] `[1 - *]` - The strength of the blur application for horizontal and vertical direction. + +
+ +### Bilateral Blur +![image_filter_box_blur](images/image_filter_box_blur.png) +> Blurring the image by bilateral algorithm. Keeps the image sharp at the edges. + +
+ Params: + +* size_[x, y] `[1 - *]` - The strength of the blur application for horizontal and vertical direction.
diff --git a/modules/ImageFilter.py b/modules/ImageFilter.py index 85b5cfc..9f51a4a 100644 --- a/modules/ImageFilter.py +++ b/modules/ImageFilter.py @@ -118,11 +118,46 @@ class ImageFilterGaussianBlur: "images": ("IMAGE",), "size_x": ("INT", { "default": 10, - "min": 1, + "min": 2, + "step": 2 }), "size_y": ("INT", { "default": 10, - "min": 1, + "min": 2, + "step": 2 + }), + }, + } + + RETURN_TYPES = ("IMAGE",) + FUNCTION = "image_filter_gaussian_blur" + CATEGORY = "image/filter" + + def image_filter_gaussian_blur(self, images, size_x, size_y): + size_x -= 1 + size_y -= 1 + + return (cv2_layer(images, lambda x: cv2.GaussianBlur(x, (size_x, size_y), size_x, size_y)),) + + +class ImageFilterGaussianBlurAdvanced: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "images": ("IMAGE",), + "size_x": ("INT", { + "default": 10, + "min": 2, + "step": 2 + }), + "size_y": ("INT", { + "default": 10, + "min": 2, + "step": 2 }), "sigma_x": ("INT", { "default": 0, @@ -138,12 +173,75 @@ class ImageFilterGaussianBlur: CATEGORY = "image/filter" def image_filter_gaussian_blur(self, images, size_x, size_y, sigma_x, sigma_y): - size_x = size_x * 2 - 1 - size_y = size_y * 2 - 1 + size_x -= 1 + size_y -= 1 return (cv2_layer(images, lambda x: cv2.GaussianBlur(x, (size_x, size_y), sigma_x, sigma_y)),) +class ImageFilterStackBlur: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "images": ("IMAGE",), + "size_x": ("INT", { + "default": 10, + "min": 1, + "step": 2 + }), + "size_y": ("INT", { + "default": 10, + "min": 1, + "step": 2 + }), + }, + } + + RETURN_TYPES = ("IMAGE",) + FUNCTION = "image_filter_stack_blur" + CATEGORY = "image/filter" + + def image_filter_stack_blur(self, images, size_x, size_y): + size_x -= 1 + size_y -= 1 + + return (cv2_layer(images, lambda x: cv2.stackBlur(x, (size_x, size_y))),) + + +class ImageFilterMedianBlur: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "images": ("IMAGE",), + "size": ("INT", { + "default": 10, + "min": 1, + "step": 2 + }), + }, + } + + RETURN_TYPES = ("IMAGE",) + FUNCTION = "image_filter_median_blur" + CATEGORY = "image/filter" + + def image_filter_median_blur(self, images, size): + size -= 1 + + img = images.clone().detach() + img = (img * 255).to(torch.uint8) + + return ((cv2_layer(img, lambda x: cv2.medianBlur(x, size)) / 255),) + + class ImageFilterBilateralBlur: def __init__(self): pass @@ -155,7 +253,8 @@ class ImageFilterBilateralBlur: "images": ("IMAGE",), "size": ("INT", { "default": 10, - "min": 1 + "min": 1, + "step": 2 }), "sigma_color": ("FLOAT", { "default": 1.0, @@ -175,71 +274,11 @@ class ImageFilterBilateralBlur: CATEGORY = "image/filter" def image_filter_bilateral_blur(self, images, size, sigma_color, sigma_intensity): - size = size * 2 - 1 + size -= 1 return (cv2_layer(images, lambda x: cv2.bilateralFilter(x, size, 100 - sigma_color * 100, sigma_intensity * 100)),) -class ImageFilterMedianBlur: - def __init__(self): - pass - - @classmethod - def INPUT_TYPES(cls): - return { - "required": { - "images": ("IMAGE",), - "size": ("INT", { - "default": 10, - "min": 1 - }), - }, - } - - RETURN_TYPES = ("IMAGE",) - FUNCTION = "image_filter_median_blur" - CATEGORY = "image/filter" - - def image_filter_median_blur(self, images, size): - size = size * 2 - 1 - - img = images.clone().detach() - img = (img * 255).to(torch.uint8) - - return ((cv2_layer(img, lambda x: cv2.medianBlur(x, size)) / 255),) - - -class ImageFilterStackBlur: - def __init__(self): - pass - - @classmethod - def INPUT_TYPES(cls): - return { - "required": { - "images": ("IMAGE",), - "size_x": ("INT", { - "default": 10, - "min": 1, - }), - "size_y": ("INT", { - "default": 10, - "min": 1, - }), - }, - } - - RETURN_TYPES = ("IMAGE",) - FUNCTION = "image_filter_stack_blur" - CATEGORY = "image/filter" - - def image_filter_stack_blur(self, images, size_x, size_y): - size_x = size_x * 2 - 1 - size_y = size_y * 2 - 1 - - return (cv2_layer(images, lambda x: cv2.stackBlur(x, (size_x, size_y))),) - - class ImageFilterContour: def __init__(self): pass @@ -490,9 +529,10 @@ NODE_CLASS_MAPPINGS = { "ImageFilterBlur": ImageFilterBlur, "ImageFilterBoxBlur": ImageFilterBoxBlur, "ImageFilterGaussianBlur": ImageFilterGaussianBlur, - "ImageFilterBilateralBlur": ImageFilterBilateralBlur, - "ImageFilterMedianBlur": ImageFilterMedianBlur, + "ImageFilterGaussianBlurAdvanced": ImageFilterGaussianBlurAdvanced, "ImageFilterStackBlur": ImageFilterStackBlur, + "ImageFilterMedianBlur": ImageFilterMedianBlur, + "ImageFilterBilateralBlur": ImageFilterBilateralBlur, "ImageFilterContour": ImageFilterContour, "ImageFilterDetail": ImageFilterDetail, "ImageFilterEdgeEnhance": ImageFilterEdgeEnhance,