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 Median Filter #259

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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: 7 additions & 2 deletions community-version.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def apply_image_filters(
"""Applies brightness, contrast, blur, and sharpen filters to the image."""

# Function to apply filters to the image
def apply_image_filters(image: Image.Image, brightness: float, contrast: float, blur: bool, sharpen: bool, gaussBlur: float, sharpRange: float) -> Image.Image:
def apply_image_filters(image: Image.Image, brightness: float, contrast: float, blur: bool, sharpen: bool, gaussBlur: float, sharpRange: float, medFilter: int) -> Image.Image:

if brightness != 1.0:
image = ImageEnhance.Brightness(image).enhance(brightness)
Expand All @@ -74,6 +74,10 @@ def apply_image_filters(image: Image.Image, brightness: float, contrast: float,

if sharpen:
image = image.filter(ImageFilter.SHARPEN)

if medFilter != 1 :
image = image.filter(ImageFilter.MedianFilter(size=medFilter))

return image


Expand Down Expand Up @@ -330,6 +334,7 @@ def run_streamlit_app():
contrast = st.sidebar.slider("Contrast", 0.5, 2.0, 1.0)
gauss_blur = st.sidebar.slider("Gaussian Blur Radius", min_value=1.0, max_value=20.0, value=1.0, step=1.0)
sharpRange = st.sidebar.slider("Sharpness", min_value=-2.0, max_value=10.0, value=1.0, step=1.0)
medFilter = st.sidebar.slider("Median Filter", min_value=1, max_value=10, value=1, step=1)
apply_blur = st.sidebar.checkbox("Apply Blur")
apply_sharpen = st.sidebar.checkbox("Apply Sharpen")

Expand Down Expand Up @@ -361,7 +366,7 @@ def run_streamlit_app():
)

# Apply filters to the image
image = apply_image_filters(image, brightness, contrast, apply_blur, apply_sharpen, gauss_blur, sharpRange)
image = apply_image_filters(image, brightness, contrast, apply_blur, apply_sharpen, gauss_blur, sharpRange, medFilter)

def get_sidebar_options():
"""Gets options from the sidebar."""
Expand Down