Giter Site home page Giter Site logo

avojak / image-morphing Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 2.0 26.01 MB

Implementation of image morphing

Jupyter Notebook 98.39% Rich Text Format 0.04% Dockerfile 0.01% Makefile 0.02% Python 0.67% HTML 0.83% CSS 0.04%
image-morphing opencv-python scipy

image-morphing's Introduction

image-morphing

Build Status

Implementation of image morphing with a web front-end. Images are uploaded, and the user selects corresponding points in the images.

Demo video: https://www.youtube.com/watch?v=S3hfBqrwQms

Input Home Page

Results Page

This was created for the CS 445 Spring 2020 Final Project at the University of Illinois at Urbana-Champaign. There are plenty of things that could be better but it works, and again this was for a school project!

Building

Install the following pre-requisite software:

  • Python 3
  • Docker (only if building the Docker image)
  • ImageMagick (only if running the test server locally)

Building the Python Packages

To build only the Python packages:

$ pip install -r requirements.txt
$ make lib web

Building the Docker Image (Recommended)

To build the Docker image:

$ make image

To build everything:

$ make all

Note that building all only makes sense if you intend to consume the Python packages directly. Otherwise simply building the Docker image will produce a portable distribution.

Running

Test Server

To run locally for testing:

$ export FLASK_APP=webmorphing; flask run

The UI will be available at http://localhost:5000.

Docker Image

A Docker image is also produced and can be run with the following command:

$ docker run -it -p 8080:8080 avojak/image-morphing:{version}

The UI will be available at http://localhost:8080.

Example Results

Sample Morph

Sample Morph

Technologies Used

Attribution

image-morphing's People

Contributors

avojak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mriffle samlaujw

image-morphing's Issues

IndexError: index 120 is out of bounds for axis 0 with size 120

Hi!

I tried your very promising app with the following couple of pictures:
bloodsplat
heart

I defined 10 control points, clicked Morph! and got the following stacktrace in the flask app logs:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "../lib/libmorphing/morphing.py", line 205, in _process_func
    frame = self._compute_frame(triangulation, t, shape, source_img, target_img, source_points, target_points)
  File "../lib/libmorphing/morphing.py", line 199, in _compute_frame
    source_val = source_img[int(source_point[1]), int(source_point[0]), c]
IndexError: index 120 is out of bounds for axis 0 with size 120
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/mnt/c/DevHome/tools/cygwin/opt/image-morphing/web/webmorphing/home.py", line 226, in thread_func
    ImageMorph(source_img_path, middle_img_path, target_img_path, source_points, middle_points, target_points,
  File "../lib/libmorphing/morphing.py", line 80, in __init__
    self._morph()
  File "../lib/libmorphing/morphing.py", line 139, in _morph
    res.get(timeout=None)
  File "/usr/local/lib/python3.8/multiprocessing/pool.py", line 771, in get
    raise self._value
IndexError: index 120 is out of bounds for axis 0 with size 120

Missaligned #source-img-canvas & #source-pts-canvas

Seems like those 2 HTML elements should be aligned, but aren't:

2021-03-13 17_05_26-Image Morphing

I'm using Firefox 86.

There is a potential fix:

diff --git a/web/webmorphing/templates/home.html b/web/webmorphing/templates/home.html
index 92a6789..91c3e5f 100644
--- a/web/webmorphing/templates/home.html
+++ b/web/webmorphing/templates/home.html
@@ -34,8 +34,8 @@
                         <div class="card box-shadow">
                             <div class="card-top">
                                 <div style="position: relative;">
-                                    <canvas class="img-canvas" id="source-img-canvas" style="position: relative; left: 0; top: 0; z-index: 0;"></canvas>
-                                    <canvas class="img-canvas" id="source-pts-canvas" style="position: absolute; left: 0; top: 0; z-index: 1;"></canvas>
+                                    <canvas class="img-canvas" id="source-img-canvas" style="position: relative; left: 0; top: 0; z-index: 0; display: block;"></canvas>
+                                    <canvas class="img-canvas" id="source-pts-canvas" style="position: absolute; left: 0; top: 0; z-index: 1; margin-top: 0;"></canvas>
                                 </div>
                                 <div class="img-canvas-placeholder justify-content-center" id="source-img-placeholder">
                                     <i class="far fa-file-image fa-7x text-muted"></i>
@@ -59,8 +59,8 @@
                         <div class="card box-shadow" id="middle-img-card" hidden>
                             <div class="card-top">
                                 <div style="position: relative;">
-                                    <canvas class="img-canvas" id="middle-img-canvas" style="position: relative; left: 0; top: 0; z-index: 0;"></canvas>
-                                    <canvas class="img-canvas" id="middle-pts-canvas" style="position: absolute; left: 0; top: 0; z-index: 1;"></canvas>
+                                    <canvas class="img-canvas" id="middle-img-canvas" style="position: relative; left: 0; top: 0; z-index: 0; display: block;"></canvas>
+                                    <canvas class="img-canvas" id="middle-pts-canvas" style="position: absolute; left: 0; top: 0; z-index: 1; margin-top: 0;"></canvas>
                                 </div>
                                 <div class="img-canvas-placeholder justify-content-center" id="middle-img-placeholder">
                                     <i class="far fa-file-image fa-7x text-muted"></i>
@@ -85,8 +85,8 @@
                         <div class="card box-shadow">
                             <div class="card-top">
                                 <div style="position: relative;">
-                                    <canvas class="img-canvas" id="target-img-canvas" style="position: relative; left: 0; top: 0; z-index: 0;"></canvas>
-                                    <canvas class="img-canvas" id="target-pts-canvas" style="position: absolute; left: 0; top: 0; z-index: 1;"></canvas>
+                                    <canvas class="img-canvas" id="target-img-canvas" style="position: relative; left: 0; top: 0; z-index: 0; display: block;"></canvas>
+                                    <canvas class="img-canvas" id="target-pts-canvas" style="position: absolute; left: 0; top: 0; z-index: 1; margin-top: 0;"></canvas>
                                 </div>
                                 <div class="img-canvas-placeholder justify-content-center" id="target-img-placeholder">
                                     <i class="far fa-file-image fa-7x text-muted"></i>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.