forked from karpathy/convnetjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ability to "upload" and test with own image in mnist and cifar1…
…0 demos
- Loading branch information
Pavel Pepeldjiyski
committed
May 7, 2015
1 parent
3ddd64f
commit e1575a8
Showing
6 changed files
with
842 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
var loadFile = function(event) { | ||
var reader = new FileReader(); | ||
reader.onload = function(){ | ||
var preview = document.getElementById('preview_img'); | ||
preview.src = centerCrop(reader.result); | ||
preview.src = resize(preview.src); | ||
}; | ||
reader.readAsDataURL(event.target.files[0]); | ||
}; | ||
|
||
function centerCrop(src){ | ||
var image = new Image(); | ||
image.src = src; | ||
|
||
var max_width = Math.min(image.width, image.height); | ||
var max_height = Math.min(image.width, image.height); | ||
|
||
var canvas = document.createElement('canvas'); | ||
var ctx = canvas.getContext("2d"); | ||
|
||
ctx.clearRect(0, 0, canvas.width, canvas.height); | ||
canvas.width = max_width; | ||
canvas.height = max_height; | ||
ctx.drawImage(image, (max_width - image.width)/2, (max_height - image.height)/2, image.width, image.height); | ||
return canvas.toDataURL("image/png"); | ||
} | ||
|
||
function resize(src){ | ||
var image = new Image(); | ||
image.src = src; | ||
|
||
var canvas = document.createElement('canvas'); | ||
canvas.width = image.width; | ||
canvas.height = image.height; | ||
var ctx = canvas.getContext("2d"); | ||
ctx.clearRect(0, 0, canvas.width, canvas.height); | ||
ctx.drawImage(image, 0, 0, image.width, image.height); | ||
|
||
var dst = document.createElement('canvas'); | ||
dst.width = image_dimension; | ||
dst.height = image_dimension; | ||
|
||
window.pica.WW = false; | ||
window.pica.resizeCanvas(canvas, dst, { | ||
quality: 2, | ||
unsharpAmount: 500, | ||
unsharpThreshold: 100, | ||
transferable: false | ||
}, function (err) { }); | ||
window.pica.WW = true; | ||
return dst.toDataURL("image/png"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.