コード例 #1
0
def picture(filename):
    picture = Picture.query.filter_by(filename=filename).first_or_404()
    size = get_size(plotpath(picture.filename))
    form = PictureForm()
    form.brushsize.default = picture.brushsize
    form.threshold.default = picture.threshold
    form.cut_x.default = 0
    form.cut_y.default = 0
    form.cut_dx.default = size[1]
    form.cut_dy.default = size[0]
    if request.method == "POST":
        if form.delete_file.data:
            deletePicture(picture.filename)
            redirect(url_for("index"))
        if form.fourplot.data:
            plot_picture(filename, cut=True)
            close_plot()
        if form.show_fourplot.data:
            plot_picture(filename, cut=True)
            show_plot()
        if form.set_threshold_brushsize.data:
            picture.brushsize = form.brushsize.data
            picture.threshold = form.threshold.data
            db.session.add(picture)
            db.session.commit()
        if form.submit_width.data:
            picture.bridge.bridgewitdh = picture.pixelwidth * picture.amplification
            db.session.add(picture)
            db.session.commit()
        if form.submit_overwrite.data:
            flash("overwrite")
            picture.pixelwidth = int(form.overwrite_width.data)
            db.session.add(picture)
            db.session.commit()
        if form.submit_cut.data:
            x = int(form.cut_x.data)
            y = int(form.cut_y.data)
            dx = int(form.cut_dx.data)
            dy = int(form.cut_dy.data)
            if x > size[1]:
                x = 0
            if x + dx > size[1]:
                dx = size[1] - x
            if y > size[0]:
                y = 0
            if y + dy > size[0]:
                dy = size[0] - y
            cut_image(picture.filename, x=x, y=y, dx=dx, dy=dy)
        return redirect(url_for("picture", filename=filename))
    if not os.path.isfile(plotpath(filename, "_cut.png")):
        #creating simple plots
        size = get_size(plotpath(picture.filename))
        cut_image(picture.filename,
                  x=10,
                  y=10,
                  dx=size[1] - 20,
                  dy=size[0] - 20)
    return render_template("picture.html", picture=picture, form=form)
コード例 #2
0
def deleteFile(filename):
    file = Document.query.filter_by(filename=filename).first()
    db.session.delete(file)
    db.session.commit()
    os.remove(filepath(filename))
    if os.path.isfile(plotpath(filename, "_plot.png")):
        os.remove(plotpath(filename, "_plot.png"))
    if os.path.isfile(plotpath(filename, "_j_C.png")):
        os.remove(plotpath(filename, "_j_C.png"))
    flash("removed all Files of: " + filename)
コード例 #3
0
def deletePicture(filename):
    picture = Picture.query.filter_by(filename=filename).first()
    db.session.delete(picture)
    db.session.commit()
    os.remove(filepath(filename))
    if os.path.isfile(plotpath(filename, "_cut.png")):
        os.remove(plotpath(filename, "_cut.png"))
    if os.path.isfile(plotpath(filename, "_4er.png")):
        os.remove(plotpath(filename, "_4er.png"))
    flash("removed all Files of: " + filename)
コード例 #4
0
def upload():
    form = UploadForm()
    if request.method == "POST":
        for f in request.files.getlist("file"):
            filename = secure_filename(f.filename)
            flash(filename)
            if filename.split(".")[1] == "txt":
                if Document.query.filter_by(
                        filename=filename).first() is not None:
                    flash("File arleady uploaded")
                    return redirect(url_for("upload"))
                new_document = Document(filename=filename)
                new_document.remove_ohm = False
                new_document.remove_offset = False
                db.session.add(new_document)
                db.session.commit()
                detect_substrate_bridge(filename)
                f.save(os.path.join(app.config["UPLOAD_FOLDER"], filename))
            elif filename.split(".")[1] == "bmp":
                if Picture.query.filter_by(
                        filename=filename).first() is not None:
                    flash("Picture already uploaded")
                    return redirect(url_for("upload"))
                new_picture = Picture(filename=filename)
                db.session.add(new_picture)
                db.session.commit()
                detect_picture_amp(filename)
                f.save(plotpath(filename))
                f.save(filepath(filename))
        return redirect(url_for("index"))
    return render_template("upload.html",
                           form=form,
                           files=Document.query.all())
コード例 #5
0
def plot_picture(filename, cut=False):
    picture = Picture.query.filter_by(filename=filename).first()
    if cut:
        img = cv2.imread(plotpath(filename, "_cut.png"))
    else:
        img = cv2.imread(plotpath(filename))
    imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    blur = cv2.GaussianBlur(imgray, (picture.brushsize, picture.brushsize), 0)

    ret, th = cv2.threshold(blur, picture.threshold, 255,
                            cv2.THRESH_TOZERO_INV)

    smalestgap = np.size(img, 0)
    gapprofile = []
    for x in range(np.size(img, 1)):
        profile = th[0:np.size(img, 0), x]
        maxima = findlocalmaxima(profile)
        if len(maxima) >= 2:
            diffmaxima = maxima[len(maxima) - 1] - maxima[0]
            gapprofile.append(diffmaxima)
            if diffmaxima < smalestgap:
                smalestgap = diffmaxima
                position = [(x, maxima[len(maxima) - 1]), (x, maxima[0])]
                bestprofile = profile
        else:
            gapprofile.append(np.size(img, 0))
    for center in position:
        cv2.circle(img, center, 5, (0, 0, 255), 2)
    picture.pixelwidth = int(smalestgap)
    db.session.add(picture)
    db.session.commit()
    plt.subplot(2, 2, 1), plt.plot(bestprofile)
    plt.ylabel("gray 0-255")
    plt.xlabel("y-position in px")
    plt.title("best profile")
    plt.subplot(2, 2, 2), plt.plot(gapprofile)
    plt.ylabel("gapdistance in px")
    plt.xlabel("x-position in px")
    plt.title("gapdistance over x")
    plt.grid(b=True, which="major", axis="y")
    plt.subplot(2, 2, 3), plt.imshow(img)
    plt.subplot(2, 2, 4), plt.imshow(th)
    plt.savefig(plotpath(filename, "_4er.png"))
コード例 #6
0
def file(filename):
    file = Document.query.filter_by(filename=filename).first_or_404()
    form = PlotForm()
    form.amplification.default = file.amplification
    form.set_border.default = file.res_border
    form2 = PlotOptionsForm()
    if request.method == "POST":
        if form.calc_j_C.data:
            plot_j_C(filename)
            close_plot()
        elif form.show_norm.data:
            plot_file(filename)
            show_plot()
        elif form.show_j_C.data:
            plot_j_C(filename)
            show_plot()
        elif form2.submit.data:
            flash(form2.checkbox.data)
            file.remove_offset = "remove_offset" in form2.checkbox.data
            file.remove_ohm = "remove_ohm" in form2.checkbox.data
            db.session.add(file)
            db.session.commit()

            plot_j_C(filename)
            close_plot()
        elif form.delete.data:
            deleteFile(filename)
            return redirect(url_for("index"))
        elif form.submit_amplification.data:
            flash(form.amplification.data)
            file.amplification = form.amplification.data
            db.session.add(file)
            db.session.commit()
        elif form.submit_I_C.data:
            file.bridge.j_C = file.j_C
            db.session.add(file)
            db.session.commit()
        elif form.submit_border.data:
            file.res_border = float(form.set_border.data)
            db.session.add(file)
            db.session.commit()

        return redirect(url_for("file", filename=filename))
    if not os.path.isfile(plotpath(filename, "_plot.png")):
        #creating simple plots
        plot_file(filename)
        close_plot()
    form.process()
    return render_template("file.html",
                           form=form,
                           form2=form2,
                           file=file,
                           files=Document.query.all())
コード例 #7
0
def cut_image(filename, x, y, dx, dy):
    img = cv2.imread(plotpath(filename))
    cut = img[y:y + dy, x:x + dx]
    cv2.imwrite(plotpath(filename, "_cut.png"), cut)