diff --git a/README.MD b/README.MD index 9e04fc6..7cd00e9 100644 --- a/README.MD +++ b/README.MD @@ -585,7 +585,7 @@ You also can change the fonts folder in config. ![image_draw_polygon](images/image_filter_smooth.png) > Anti-Aliasing of image artifacts. -### SmoothMore +### Smooth More ![image_filter_smooth_more](images/image_filter_smooth_more.png) > Improved Anti-Aliasing of image artifacts. @@ -593,7 +593,7 @@ You also can change the fonts folder in config. ![image_filter_blur](images/image_filter_blur.png) > Blurring the image. -### BoxBlur +### Box Blur ![image_filter_box_blur](images/image_filter_box_blur.png) > Blurring the image by box algorithm. @@ -604,7 +604,7 @@ You also can change the fonts folder in config. -### GaussianBlur +### Gaussian Blur ![image_filter_gaussian_blur](images/image_filter_gaussian_blur.png) > Blurring the image by gaussian algorithm. @@ -615,6 +615,17 @@ You also can change the fonts folder in config. +### Median Blur +![image_filter_median](images/image_filter_median.png) +> Selects the average pixel value in a window of the specified size. + +
+ Params: + +* size `[0 - *]` - The size of the core in PX. + +
+ ### Contour ![image_filter_contour](images/image_filter_contour.png) > Find the contours of the image. @@ -623,11 +634,11 @@ You also can change the fonts folder in config. ![image_filter_detail](images/image_filter_detail.png) > Image detailing. -### EdgeEnhance +### Edge Enhance ![image_filter_edge_enhance](images/image_filter_edge_enhance.png) > Clarity of the image boundaries. -### EdgeEnhanceMore +### Edge Enhance More ![image_filter_edge_enhance_more](images/image_filter_edge_enhance_more.png) > Improved clarity of image boundaries. @@ -635,7 +646,7 @@ You also can change the fonts folder in config. ![image_filter_emboss](images/image_filter_emboss.png) > Embossed image. -### FindEdges +### Find Edges ![image_filter_find_edges](images/image_filter_find_edges.png) > Identifies the boundaries of the image. @@ -655,17 +666,6 @@ You also can change the fonts folder in config. -### Median -![image_filter_median](images/image_filter_median.png) -> Selects the average pixel value in a window of the specified size. - -
- Params: - -* size `[0 - *]` - The size of the core in PX. - -
- ### Min ![image_filter_min](images/image_filter_min.png) > Selects the smallest pixel value in the window at the specified size. diff --git a/modules/ImageFilter.py b/modules/ImageFilter.py index 2de6970..5b50088 100644 --- a/modules/ImageFilter.py +++ b/modules/ImageFilter.py @@ -155,6 +155,34 @@ class ImageFilterBilateralBlur: 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 + }), + }, + } + + 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 ImageFilterStackBlur: def __init__(self): pass @@ -178,10 +206,10 @@ class ImageFilterStackBlur: } RETURN_TYPES = ("IMAGE",) - FUNCTION = "image_filter_bilateral_blur" + FUNCTION = "image_filter_stack_blur" CATEGORY = "image/filter" - def image_filter_bilateral_blur(self, images, size_x, size_y): + def image_filter_stack_blur(self, images, size_x, size_y): size_x -= 1 size_y -= 1 @@ -357,31 +385,6 @@ class ImageFilterRank: return applyImageFilter(images, ImageFilter.RankFilter(int(size) + 1, rank)) -class ImageFilterMedian: - def __init__(self): - pass - - @classmethod - def INPUT_TYPES(cls): - return { - "required": { - "images": ("IMAGE",), - "size": ("INT", { - "default": 2, - "min": 0, - "step": 2 - }), - }, - } - - RETURN_TYPES = ("IMAGE",) - FUNCTION = "image_filter_median" - CATEGORY = "image/filter" - - def image_filter_median(self, images, size): - return applyImageFilter(images, ImageFilter.MedianFilter(int(size) + 1)) - - class ImageFilterMin: def __init__(self): pass @@ -464,6 +467,7 @@ NODE_CLASS_MAPPINGS = { "ImageFilterBoxBlur": ImageFilterBoxBlur, "ImageFilterGaussianBlur": ImageFilterGaussianBlur, "ImageFilterBilateralBlur": ImageFilterBilateralBlur, + "ImageFilterMedianBlur": ImageFilterMedianBlur, "ImageFilterStackBlur": ImageFilterStackBlur, "ImageFilterContour": ImageFilterContour, "ImageFilterDetail": ImageFilterDetail, @@ -473,7 +477,6 @@ NODE_CLASS_MAPPINGS = { "ImageFilterFindEdges": ImageFilterFindEdges, "ImageFilterSharpen": ImageFilterSharpen, "ImageFilterRank": ImageFilterRank, - "ImageFilterMedian": ImageFilterMedian, "ImageFilterMin": ImageFilterMin, "ImageFilterMax": ImageFilterMax, "ImageFilterMode": ImageFilterMode