Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaiPetukhov committed Sep 22, 2023
1 parent ea5864c commit e468c91
Show file tree
Hide file tree
Showing 60 changed files with 3,210 additions and 2,056 deletions.
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ git+https://github.com/supervisely/supervisely.git@NikolaiPetukhov
jsonschema
networkx
scikit-image>=0.17.1, <1.0.0
cacheout
cacheout
markdown
json2html
58 changes: 24 additions & 34 deletions src/compute/layers/processing/BlurLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@


class BlurLayer(Layer):

action = 'blur'
action = "blur"

layer_settings = {
"required": ["settings"],
Expand All @@ -22,62 +21,53 @@ class BlurLayer(Layer):
"oneOf": [
{
"type": "object",
"required": [
"name",
"sigma"
],
"required": ["name", "sigma"],
"properties": {
"name": {
"type": "string",
"enum": [
"gaussian",
]
],
},
"sigma": {
"type": "object",
"required": ["min", "max"],
"properties": {
"min": {"type": "number", "minimum": 0.01},
"max": {"type": "number", "minimum": 0.01},
}
}
}
},
},
},
},
{
"type": "object",
"required": [
"name",
"kernel"
],
"required": ["name", "kernel"],
"properties": {
"name": {
"type": "string",
"enum": [
"median",
]
],
},
"kernel": {
"type": "integer",
"minimum": 3
}
}
}
]
"kernel": {"type": "integer", "minimum": 3},
},
},
],
}
}
},
}

def __init__(self, config):
Layer.__init__(self, config)
if (self.settings['name'] == 'median') and (self.settings['kernel'] % 2 == 0):
raise RuntimeError('Kernel for median blur must be odd.')
if (self.settings["name"] == "median") and (self.settings["kernel"] % 2 == 0):
raise RuntimeError("Kernel for median blur must be odd.")

def check_min_max(dictionary, text):
if dictionary['min'] > dictionary['max']:
if dictionary["min"] > dictionary["max"]:
raise RuntimeError('"min" should be <= than "max" for "{}".'.format(text))

if self.settings['name'] == 'gaussian':
check_min_max(self.settings['sigma'], 'sigma')
if self.settings["name"] == "gaussian":
check_min_max(self.settings["sigma"], "sigma")

def requires_image(self):
return True
Expand All @@ -86,13 +76,13 @@ def process(self, data_el: Tuple[ImageDescriptor, Annotation]):
img_desc, ann = data_el

img = img_desc.read_image()
img = img.astype(np.float32)
if self.settings['name'] == 'gaussian':
sigma_b = self.settings['sigma']
sigma_value = np.random.uniform(sigma_b['min'], sigma_b['max'])
img = img.astype(np.uint8)
if self.settings["name"] == "gaussian":
sigma_b = self.settings["sigma"]
sigma_value = np.random.uniform(sigma_b["min"], sigma_b["max"])
res_img = cv2.GaussianBlur(img, ksize=(0, 0), sigmaX=sigma_value)
elif self.settings['name'] == 'median':
res_img = cv2.medianBlur(img, ksize=self.settings['kernel'])
elif self.settings["name"] == "median":
res_img = cv2.medianBlur(img, ksize=self.settings["kernel"])
else:
raise NotImplementedError()

Expand Down
12 changes: 12 additions & 0 deletions src/globals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import queue
from dotenv import load_dotenv

import supervisely as sly
Expand Down Expand Up @@ -29,3 +30,14 @@

layers_count = 0
layers = {}


update_queue = queue.Queue()


def updater(update: str):
global update_queue
update_queue.put(update)


context_menu_position = None
5 changes: 4 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import shutil
import os
import threading
from supervisely import Application

from src.ui.ui import layout
from src.ui.ui import layout, update_loop
import src.globals as g

shutil.rmtree(g.STATIC_DIR, ignore_errors=True)
os.mkdir(g.STATIC_DIR)
app = Application(layout=layout, static_dir=g.STATIC_DIR)

update_loop.start()
17 changes: 6 additions & 11 deletions src/ui/dtl/Action.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,34 @@
from typing import Optional

from supervisely.app.widgets import NodesFlow, Container, Text
import src.globals as g


class Action:
name = None
title = None
docs_url = None
description = None
md_description = ""
width = 340
# when setting options from settings json, values from _settings_mapping will be mapped to options.
# If there is no option mapped directly to setting, set this option mapping to None and set the option value
# in set_settings_from_json function. If option name is different from setting name - set mapping in
# _settings_mapping below. If option name is the same as setting name - no need to set mapping.
_settings_mapping = {}

@classmethod
def create_new_layer(cls, layer_id: Optional[str] = None):
raise NotImplementedError

@classmethod
def create_inputs(cls):
return [NodesFlow.Node.Input("source", "Source")]
return [NodesFlow.Node.Input("source", "Input")]

@classmethod
def create_outputs(cls):
return [NodesFlow.Node.Output("destination", "Destination")]
return [NodesFlow.Node.Output("destination", "Output")]

@classmethod
def create_info_widget(cls):
return Container(
widgets=[
Text(f"<h3>{cls.title}</h3>", color="white"),
Text(f'<a href="{cls.docs_url}" target="_blank" style="color: white;">Docs</a>'),
Text(f"<p>{cls.description}</p>", color="white"),
Text(f"<h3>{cls.title}</h3>"),
Text(f'<a href="{cls.docs_url}" target="_blank">Docs</a>'),
Text(f"<p>{cls.description}</p>"),
]
)
Loading

0 comments on commit e468c91

Please sign in to comment.