Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added new filters #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions operators/ApplyBlurFilterOperator/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "ApplyCV2FilterOperator",
BrunoSerafim marked this conversation as resolved.
Show resolved Hide resolved
"dependency": {
"dockerfile": "Dockerfile_0"
},
"tags": [
"Example"
]
}
35 changes: 35 additions & 0 deletions operators/ApplyBlurFilterOperator/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from pydantic import BaseModel, Field
from enum import Enum

class EffectType(str, Enum):
averaging = "averaging"
gaussianblurring = "gaussianblurring"
medianblurring = "medianblurring"
bilateralfiltering = "bilateralfiltering"

class InputModel(BaseModel):
"""
Apply effect to image
"""

input_file_path: str = Field(
description="Path to the input file"
)
effect: EffectType = Field(
default='gaussianblurring',
description='Effect to be applied'
)


class OutputModel(BaseModel):
"""
Apply effect to image
"""

message: str = Field(
default="",
description="Output message to log"
)
output_file_path: str = Field(
description="Path to the output file"
)
44 changes: 44 additions & 0 deletions operators/ApplyBlurFilterOperator/operator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from flowui.base_operator import BaseOperator
from .models import InputModel, OutputModel
from pathlib import Path
import cv2


# greyscale filter
def apply_averaging(img):
return cv2.blur(img,(5,5))

def apply_gaussianblurring(img):
return cv2.GaussianBlur(img,(5,5),0)

def apply_medianblurring(img):
return cv2.medianBlur(img,5)

def apply_bilateralfiltering(img):
return cv2.bilateralFilter(img,9,75,75)

class ApplyBlurFilter(BaseOperator):

def operator_function(self, input_model: InputModel):
#Read the image
image = cv2.imread(input_model.input_file_path)

effect_types_map = dict(
averaging = apply_averaging,
gaussianblurring = apply_gaussianblurring,
medianblurring = apply_medianblurring,
bilateralfiltering = apply_bilateralfiltering,
)

chosen_effect = input_model.effect

image_processed = effect_types_map[chosen_effect](img=image)

# Save result
out_file_path = str(Path(self.results_path) / Path(input_model.input_file_path).name)
cv2.imwrite(out_file_path, image_processed)

return OutputModel(
message=f"Filtered image successfully saved to: {out_file_path}",
output_file_path=str(out_file_path)
)
4 changes: 2 additions & 2 deletions operators/ApplyCV2FilterOperator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def apply_sepia(img):
)
img_sepia[np.where(img_sepia > 255)] = 255 # normalizing values greater than 255 to 255
img_sepia = np.array(img_sepia, dtype=np.uint8)
return
return img_sepia
BrunoSerafim marked this conversation as resolved.
Show resolved Hide resolved

# pencil filter
def apply_pencil(img):
Expand Down Expand Up @@ -118,4 +118,4 @@ def operator_function(self, input_model: InputModel):
return OutputModel(
message=f"Filtered image successfully saved to: {out_file_path}",
output_file_path=str(out_file_path)
)
)
9 changes: 9 additions & 0 deletions operators/ApplyEdgeFilterOperator/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "ApplyCV2FilterOperator",
"dependency": {
"dockerfile": "Dockerfile_0"
},
"tags": [
"Example"
],
}
25 changes: 25 additions & 0 deletions operators/ApplyEdgeFilterOperator/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from pydantic import BaseModel, Field


class InputModel(BaseModel):
"""
Apply effect to image
"""

input_file_path: str = Field(
description="Path to the input file"
)


class OutputModel(BaseModel):
"""
Apply effect to image
"""

message: str = Field(
default="",
description="Output message to log"
)
output_file_path: str = Field(
description="Path to the output file"
)
25 changes: 25 additions & 0 deletions operators/ApplyEdgeFilterOperator/operator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from flowui.base_operator import BaseOperator
from .models import InputModel, OutputModel

from pathlib import Path
import random
import cv2
import numpy as np
from scipy.interpolate import UnivariateSpline


class ApplyEdgeFilter(BaseOperator):

def operator_function(self, input_model: InputModel):
#Read the image
image = cv2.imread(input_model.input_file_path)
image_processed = cv2.Canny(image,100,200)

# Save result
out_file_path = str(Path(self.results_path) / Path(input_model.input_file_path).name)
cv2.imwrite(out_file_path, image_processed)

return OutputModel(
message=f"Filtered image successfully saved to: {out_file_path}",
output_file_path=str(out_file_path)
)
9 changes: 9 additions & 0 deletions operators/ApplyGradientFilterOperator/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "ApplyCV2FilterOperator",
"dependency": {
"dockerfile": "Dockerfile_0"
},
"tags": [
"Example"
]
}
34 changes: 34 additions & 0 deletions operators/ApplyGradientFilterOperator/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from pydantic import BaseModel, Field
from enum import Enum

class EffectType(str, Enum):
laplacian = "laplacian"
sobelx = "sobelx"
sobely = "sobely"

class InputModel(BaseModel):
"""
Apply effect to image
"""

input_file_path: str = Field(
description="Path to the input file"
)
effect: EffectType = Field(
default='laplacian',
description='Effect to be applied'
)


class OutputModel(BaseModel):
"""
Apply effect to image
"""

message: str = Field(
default="",
description="Output message to log"
)
output_file_path: str = Field(
description="Path to the output file"
)
41 changes: 41 additions & 0 deletions operators/ApplyGradientFilterOperator/operator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from flowui.base_operator import BaseOperator
from .models import InputModel, OutputModel

from pathlib import Path
import cv2

def apply_laplacian(img):
return cv2.Laplacian(img,cv2.CV_64F)

def apply_sobelx(img):
return cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5)

def apply_sobely(img):
return cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5)



class ApplyGradientFilter(BaseOperator):

def operator_function(self, input_model: InputModel):
#Read the image
image = cv2.imread(input_model.input_file_path)

effect_types_map = dict(
laplacian = apply_laplacian,
sobelx = apply_sobelx,
sobely = apply_sobely,
)

chosen_effect = input_model.effect

image_processed = effect_types_map[chosen_effect](img=image)

# Save result
out_file_path = str(Path(self.results_path) / Path(input_model.input_file_path).name)
cv2.imwrite(out_file_path, image_processed)

return OutputModel(
message=f"Filtered image successfully saved to: {out_file_path}",
output_file_path=str(out_file_path)
)
9 changes: 9 additions & 0 deletions operators/ApplyGrayscaleFilterOperator/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "ApplyCV2FilterOperator",
"dependency": {
"dockerfile": "Dockerfile_0"
},
"tags": [
"Example"
]
}
25 changes: 25 additions & 0 deletions operators/ApplyGrayscaleFilterOperator/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from pydantic import BaseModel, Field


class InputModel(BaseModel):
"""
Apply effect to image
"""

input_file_path: str = Field(
description="Path to the input file"
)


class OutputModel(BaseModel):
"""
Apply effect to image
"""

message: str = Field(
default="",
description="Output message to log"
)
output_file_path: str = Field(
description="Path to the output file"
)
23 changes: 23 additions & 0 deletions operators/ApplyGrayscaleFilterOperator/operator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from flowui.base_operator import BaseOperator
from .models import InputModel, OutputModel

from pathlib import Path
import cv2


class ApplyGrayscaleFilter(BaseOperator):

def operator_function(self, input_model: InputModel):
#Read the image
image = cv2.imread(input_model.input_file_path)

image_processed = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Save result
out_file_path = str(Path(self.results_path) / Path(input_model.input_file_path).name)
cv2.imwrite(out_file_path, image_processed)

return OutputModel(
message=f"Filtered image successfully saved to: {out_file_path}",
output_file_path=str(out_file_path)
)
9 changes: 9 additions & 0 deletions operators/ApplyMorphologicalFilterOperator/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "ApplyCV2FilterOperator",
"dependency": {
"dockerfile": "Dockerfile_0"
},
"tags": [
"Example"
]
}
38 changes: 38 additions & 0 deletions operators/ApplyMorphologicalFilterOperator/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from pydantic import BaseModel, Field
from enum import Enum

class EffectType(str, Enum):
erosion = "erosion"
dilation = "dilation"
opening = "opening"
closing = "closing"
morphologicalgradient = "morphologicalgradient"
tophat = "tophat"
blackhat = "blackhat"

class InputModel(BaseModel):
"""
Apply effect to image
"""

input_file_path: str = Field(
description="Path to the input file"
)
effect: EffectType = Field(
default='erosion',
description='Effect to be applied'
)


class OutputModel(BaseModel):
"""
Apply effect to image
"""

message: str = Field(
default="",
description="Output message to log"
)
output_file_path: str = Field(
description="Path to the output file"
)
Loading