Skip to content
Open
Show file tree
Hide file tree
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
Binary file added Snail_GT.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 27 additions & 25 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from dash.exceptions import PreventUpdate

from utils import (parse_jsonstring, segmentation_generic,
image_with_contour, image_string_to_PILImage)
image_with_contour, image_without_contour, image_string_to_PILImage)
from dash_canvas.components import image_upload_zone

import subprocess
Expand Down Expand Up @@ -60,14 +60,17 @@
image_upload_zone('upload-image'),

]),
dcc.Tab(
label='Ground Truth Image',
value='ground-truth-tab',
children=[
html.Img(id='ground-truth',
src='assets/Snailcpy_GT.jpg',
width='100%'),
]),
#dcc.Tab(
# label='Ground Truth Image',
#value='ground-truth-tab',
#children=[
# dcc.Graph(
# id='ground-truth',
#figure=image_with_contour('assets/Snailcpy_GT.jpg',
# img > 0, shape=(height, width))
#)

#]),
dcc.Tab(
label='Segmentation result',
value='segmentation-result-tab',
Expand All @@ -76,7 +79,12 @@
id='segmentation',
figure=image_with_contour(np.ones_like(img),
img > 0, shape=(height, width))
)
),
# dcc.Graph(
#id='ground-truth2',
#figure=image_with_contour('assets/Snailcpy_GT.jpg',
# img > 0, shape=(height, width))
#)
]),
dcc.Tab(
label='How to use this app',
Expand Down Expand Up @@ -113,6 +121,7 @@
id='algorithm',
options=[
{'label': 'Watershed', 'value': 'watershed'},
{'label': 'GeneticSearch', 'value': 'genetic_search'},
{'label': 'Random Walker', 'value': 'random_walker'},
{'label': 'Random Forest', 'value': 'random_forest'}
],
Expand All @@ -126,12 +135,14 @@
[Input('canvas', 'json_data')],
[State('canvas', 'image_content'),
State('algorithm', 'value')])
def update_figure_upload(string, image, algorithm):
#create button to read current directory, if mask file exists in current dir, read it and display results
def update_figure_upload(string, image, algorithm):
print("update figure")
if string:
if image is None:
im = img
image = img
# if seg exists calculate mask
else:
#print("Before PILImage")
im = image_string_to_PILImage(image)
Expand All @@ -144,42 +155,32 @@ def update_figure_upload(string, image, algorithm):
#skimage.io.imsave("medial.png", img_as_uint(imgSk))

io.imsave("Snail_GT.jpg", mask)
file_copy("Snail_GT.jpg", "assets/Snailcpy_GT.jpg")

#file_copy function can be removed, the code below can be called----
#shutil.copyfile("Snail_GT.jpg", "assets/Snailcopy1_GT.jpg")


#import subprocess
if mask.sum() > 0:
#ERRORS-
#CommandNotFound Error Message: Your shell has not been properly configured to use 'conda activate'
#FileNotFound: python: can't open file 'GeneticSearch.py': [Errno 2] No such file or directory

#command1 = subprocess.Popen(['python GeneticSearch.py', './assets/Snail.jpg', './assets/Snail_GT.jpg'])
#command1 = subprocess.Popen(['bash -c "conda activate root; python GeneticSearch.py"', './assets/Snail_resize.jpg', './assets/Snail_GT.jpg'], shell=True)
#subprocess.Popen(['conda run -n env; python GeneticSearch.py', './assets/Snail_resize.jpg', './assets/Snail_GT.jpg'], shell=True)
seg = segmentation_generic(im, mask, mode=algorithm)

else:
seg = np.zeros(shape)

return image_with_contour(im, seg, shape=shape)
else:
raise PreventUpdate


#This function can be removed and shutil.copfile() can be used in the update_figure_upload function
def file_copy(src, dest):
#Copy the source to destination
shutil.copyfile(src, dest) #Update dest filename after each segmentation
return

@app.callback(Output('canvas', 'image_content'),
[Input('upload-image', 'contents')])
def update_canvas_upload(image_string):
# The line below causes NoneType Error
if image_string is None:
raise PreventUpdate
else:
else:
print("uploading", image_string[:100])
return image_string

Expand All @@ -192,6 +193,7 @@ def change_focus(string):
return 'segmentation-canvas-tab'



if __name__ == '__main__':
app.run_server(debug=True)

Binary file added assets/Snail_resize.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Snailcpy4_GT.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Snailcpy_GT.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mask.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions monitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Monitoring files for changes
# pip install watchdog

import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

class MyHandler(FileSystemEventHandler):
def on_modified(self, event):
print("{event.src_path} has been modified")

event_handler = MyHandler()
observer = Observer()
observer.schedule(event_handler, path = '.', recursive=False)
observer.start()

try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()

# watchdog in javascript?

# When you run this program and make any changes to any file in current directory,
# the on_modified function from MyHandler class gets called with the event.
# In the MyHandler class you can define your own functions to handle the events.
# In the path, you can specify the files/directories you want to monitor.
# To stop this program, use Ctrl + C

# Monitor a filesystem and react when a change occurs, so that I can check for the segmentation mask in the directory
Loading