Commit dc2a970e authored by Elijah Justin Medina's avatar Elijah Justin Medina
Browse files

initial commit

parents
from flask import Flask, jsonify, render_template
import os
import imageio
import numpy as np
import scipy.misc
import glob
from skimage.morphology import binary_erosion, binary_dilation
app = Flask(__name__, static_folder="web")
@app.route('/images')
def serve_images():
return jsonify(os.listdir('data/images'))
@app.route('/threshold/<string:img>/<int:R_min>/<int:R_max>/<int:G_min>/<int:G_max>/<int:B_min>/<int:B_max>')
def threshold_image(img, R_min, R_max, G_min, G_max, B_min, B_max):
# files = glob.glob('web/data/thresholded/*')
# os.remove(files[0])
delete_files('thresholded')
# morph_delete_files()
img_arr = imageio.imread(f'data/images/{img}')
R = img_arr[:, :, 0]
G = img_arr[:, :, 1]
B = img_arr[:, :, 2]
mask = ((R>R_min) & (R<R_max) & (G>G_min) & (G<G_max) & (B>B_min) & (B<B_max))
# imageio.imwrite("web/data/thresholded-mask.png", mask.astype(np.uint8)*255)
imageio.imwrite(f"web/data/thresholded/{img.replace('.','-')}-{R_min}-{R_max}-{G_min}-{G_max}-{B_min}-{B_max}.png", mask.astype(np.uint8)*255)
imageio.imwrite(f"web/data/morph/morph_init.png", mask.astype(np.uint8)*255)
return ('', 204)
def delete_files(folder):
files = glob.glob(f'web/data/{folder}/*')
os.remove(files[0])
@app.route('/apply_mask/<string:img>/<int:R_min>/<int:R_max>/<int:G_min>/<int:G_max>/<int:B_min>/<int:B_max>')
def apply_mask(img, R_min, R_max, G_min, G_max, B_min, B_max):
delete_files('masked_img')
files = glob.glob('web/data/thresholded/*')
mask = imageio.imread(files[0])
img_arr = imageio.imread(f'data/images/{img}')
img_out = img_arr*(mask//255).reshape(*mask.shape, 1)
imageio.imwrite(f"web/data/masked_img/{img.replace('.','-')}-{R_min}-{R_max}-{G_min}-{G_max}-{B_min}-{B_max}.png", img_out)
return ('', 204)
def morph_delete_files():
files = glob.glob(f'web/data/morph/morph_new_*')
os.remove(files[0])
operations = {'dilation':binary_dilation, 'erosion':binary_erosion}
@app.route('/morph/<string:process>/<string:img>/<int:radius>')
def morph(process, img, radius):
op = operations[process]
selem = np.zeros((50, 50))
# mask = imageio.imread(filenames[-1])
files = glob.glob(f'web/data/morph/morph_new*')
if files:
mask = imageio.imread(files[0])
else:
mask = imageio.imread(f'web/data/morph/morph_init.png')
morph_delete_files()
ci = 25
cj = 25
# Create index arrays to z
I,J=np.meshgrid(np.arange(50),np.arange(50))
# calculate distance of all points to centre
dist=np.sqrt((I-ci)**2+(J-cj)**2)
# Assign value of 1 to those points where dist<cr:
selem[np.where(dist<=radius)]=1
mask_new = op(mask, selem)
imageio.imwrite(f"web/data/morph/morph_new_{img.replace('.','-')}-{radius}-{process}.png", mask_new.astype(np.uint8)*255)
# filenames.append("web/data/morph/morph_new_{img.replace('.','-')}-{radius}-{process}.png")
return ('', 204)
# @app.route('/maskthres')
\ No newline at end of file
.slider {
-webkit-appearance: none;
width: 90%;
height: 25px;
position: absolute;
background: #a4a4a4;
outline: none;
}
.slider input {
pointer-events: none;
position: absolute;
overflow: hidden;
left: 25%;
top: 15px;
width: 50%;
outline: none;
height: 18px;
margin: 0;
padding: 0;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 35px;
height: 35px;
background: #ea4550;
cursor: pointer;
pointer-events: all;
position: relative;
z-index: 1;
outline: 0;
}
.slider::-moz-range-thumb {
width: 20px;
height: 20px;
background: #ea4550;
cursor: pointer;
pointer-events: all;
position: relative;
z-index: 10;
-moz-appearance: none;
width: 9px;
}
.slider input::-moz-range-track {
position: relative;
z-index: -1;
border: 0;
}
.slider input:last-of-type::-moz-range-track {
-moz-appearance: none;
background: none transparent;
border: 0;
}
.slider input[type=range]::-moz-focus-outer {
border: 0;
}
#img-container {
width: 256px;
height: 256px;
text-align: center;
}
img {
max-width: 100%;
max-height: 100%;
margin: 15px 5px;
}
.slider {
position: relative;
margin-left: 10px;
}
.slider#higher {
top: -30px;
}
.slider.red {
background: linear-gradient(to right, rgb(0,0,0) , rgb(255,0,0) );
}
.slider.green {
background: linear-gradient(to right, rgb(0,0,0) , rgb(0,255,0) );
}
.slider.blue {
background: linear-gradient(to right, rgb(0,0,0) , rgb(0,0,255) );
}
.slidecontainer {
width: 33%;
display: inline-block;
padding: 0px;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment