-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jonathanlurie/dev
Dev
- Loading branch information
Showing
18 changed files
with
1,091 additions
and
275 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,79 @@ | ||
<html> | ||
<head> | ||
<title>URL to Image2D</title> | ||
|
||
<script src="../dist/pixpipe.js"></script> | ||
|
||
<style> | ||
canvas, | ||
.smaller{ | ||
width: 50vw; | ||
height: auto; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<p> | ||
<p>The original image</p> | ||
<img class="smaller" src="images/sd.jpg"></img> | ||
</p> | ||
|
||
<p> | ||
<p>The transformed image, with switched chanels</p> | ||
<div class="smaller" id="myDiv"></div> | ||
</p> | ||
|
||
<script> | ||
|
||
// create a filter to write the image into a canvas | ||
var imageToCanvasFilter = new pixpipe.CanvasImageWriter(); | ||
imageToCanvasFilter.setMetadata( "parentDivID", "myDiv" ); | ||
|
||
// The filter to read image from URL | ||
var url2ImgFilter = new pixpipe.UrlImageReader(); | ||
|
||
// the image is loaded... | ||
// here, filter = url2ImgFilter | ||
url2ImgFilter.on( "imageLoaded", function(filter){ | ||
|
||
var forEachPixelFilter = new pixpipe.ForEachPixelImageFilter(); | ||
|
||
// add the input input | ||
forEachPixelFilter.addInput( url2ImgFilter.getOutput() ); | ||
|
||
// Apply this treatment to each pixel of the image. | ||
// args: | ||
// position: 2D position of current pixel as an Object {x, y} | ||
// color: array of colors of the current pixel. | ||
// | ||
// Must return, or null to not modify the current color, | ||
// or an array of the same size of color. | ||
forEachPixelFilter.on( "pixel", function(position, color){ | ||
return [ | ||
color[1], // red (takes the values from green) | ||
color[0], // green (takes the values from red) | ||
color[2] * 0.5, // blue get 50% darker | ||
255 // alpha, at max | ||
] | ||
}); | ||
|
||
// run the filter | ||
forEachPixelFilter.update(); | ||
|
||
// use the output of the UrlImageReader as the input for CanvasImageWriter | ||
imageToCanvasFilter.addInput( forEachPixelFilter.getOutput() ); | ||
// actually copy the data from the Image2D into the inner HTML5 canvas | ||
imageToCanvasFilter.update(); | ||
}); | ||
|
||
// the input of this reader is a simple string url. Can be local of distant, but if distant, the server must allow CORS. | ||
url2ImgFilter.addInput( "images/sd.jpg" ); | ||
|
||
// Ask to fetch the image from URL | ||
url2ImgFilter.update(); | ||
|
||
|
||
</script> | ||
|
||
</body> | ||
</html> |
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
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
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,28 @@ | ||
/* | ||
* Author Jonathan Lurie - http://me.jonahanlurie.fr | ||
* License MIT | ||
* Link https://github.com/jonathanlurie/pixpipejs | ||
* Lab MCIN - Montreal Neurological Institute | ||
*/ | ||
|
||
import { Filter } from './Filter.js'; | ||
import { Image2D } from './Image2D.js'; | ||
|
||
/** | ||
* ImageToImageFilter is not to be used as-is but rather as a base class for any | ||
* filter that input a single Image2D and output a single Image2D. | ||
* This class does not overload the update() method. | ||
*/ | ||
class ImageToImageFilter extends Filter { | ||
|
||
constructor(){ | ||
super(); | ||
this._inputValidator[ 0 ] = Image2D.TYPE(); | ||
|
||
// will be a copy of the input Image2D buffer | ||
this._inputBuffer = null; | ||
} | ||
|
||
} /* END class ImageToImageFilter */ | ||
|
||
export { ImageToImageFilter } |
Oops, something went wrong.