forked from jywarren/image-sequencer
-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add arbitrary crop module #1607
Draft
rishabhshuklax
wants to merge
6
commits into
publiclab:main
Choose a base branch
from
rishabhshuklax:arbitrary-crop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9df0d1b
add arbitrary crop
rishabhshuklax 230ef58
Merge branch 'main' into arbitrary-crop
rishabhshuklax 98e320b
added functionality to crop the image to remove redundand pixels
rishabhshuklax a148ca0
Merge branch 'arbitrary-crop' of https://github.com/blurry-x-face/ima…
rishabhshuklax 8c7252a
add description for module
rishabhshuklax 3c4892a
Merge branch 'main' into arbitrary-crop
harshkhandeparkar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,104 @@ | ||
module.exports = function ArbitraryCrop(options, UI, util) { | ||
var defaults = require('../../util/getDefaults.js')(require('./info.json')); | ||
|
||
options.x1 = options.x1 || defaults.x1; | ||
options.y1 = options.y1 || defaults.y1; | ||
options.x2 = options.x2 || defaults.x2; | ||
options.y2 = options.y2 || defaults.y2; | ||
options.x3 = options.x3 || defaults.x3; | ||
options.y3 = options.y3 || defaults.y3; | ||
options.x4 = options.x4 || defaults.x4; | ||
options.y4 = options.y4 || defaults.y4; | ||
|
||
var output; | ||
|
||
// This function is called on every draw. | ||
function draw(input, callback, progressObj) { | ||
progressObj.stop(true); | ||
progressObj.overrideFlag = true; | ||
|
||
var step = this; | ||
|
||
var x1 = options.x1, | ||
y1 = options.y1, | ||
x2 = options.x2, | ||
y2 = options.y2, | ||
x3 = options.x3, | ||
y3 = options.y3, | ||
x4 = options.x4, | ||
y4 = options.y4; | ||
|
||
// Equation of line l1. | ||
function l1(x, y) { | ||
var d = (x - x1) * (y2 - y1) - (y - y1) * (x2 - x1); | ||
return d; | ||
} | ||
|
||
// Equation of line l2. | ||
function l2(x, y) { | ||
var d = (x - x2) * (y4 - y2) - (y - y2) * (x4 - x2); | ||
return d; | ||
} | ||
|
||
// Equation of line l3. | ||
function l3(x, y) { | ||
var d = (x - x3) * (y4 - y3) - (y - y3) * (x4 - x3); | ||
return d; | ||
} | ||
|
||
// Equation of line l4. | ||
function l4(x, y) { | ||
var d = (x - x1) * (y3 - y1) - (y - y1) * (x3 - x1); | ||
return d; | ||
} | ||
|
||
function changePixel(r, g, b, a, x, y) { | ||
|
||
if(l1(x, y) * l3(x, y) <= 0 && l2(x, y) * l4(x, y) <= 0) return [r, g, b, a]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey is this the formula that determines whether the point is inside the quadrilateral? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
|
||
else return [r, g, b, 0]; | ||
} | ||
|
||
function extraManipulation(pixels) { | ||
|
||
x = Math.min(x1, x2, x3, x4); | ||
y = Math.min(y1, y2, y3, y4); | ||
|
||
w = Math.max(x1, x2, x3, x4); | ||
h = Math.max(y1, y2, y3, y4); | ||
|
||
newPixels = require('../Crop/Crop')(pixels, {x, y, w, h}); | ||
|
||
return newPixels; | ||
|
||
} | ||
|
||
function output(image, datauri, mimetype, wasmSuccess) { | ||
step.output = { | ||
src: datauri, | ||
format: mimetype, | ||
wasmSuccess, | ||
useWasm: options.useWasm | ||
}; | ||
} | ||
|
||
return require('../_nomodule/PixelManipulation.js')(input, { | ||
output: output, | ||
ui: options.step.ui, //don't pass this in if you don't want your module to support progress bars | ||
changePixel: changePixel, | ||
format: input.format, | ||
image: options.image, | ||
inBrowser: options.inBrowser, | ||
callback: callback, | ||
useWasm: options.useWasm, | ||
extraManipulation | ||
}); | ||
} | ||
|
||
return { | ||
options: options, | ||
draw: draw, | ||
output: output, | ||
UI: UI | ||
}; | ||
}; |
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,4 @@ | ||
module.exports = [ | ||
require('./Module'), | ||
require('./info.json') | ||
]; |
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,48 @@ | ||
{ | ||
"name": "arbitrary-crop", | ||
"description": "Crops image for any arbitrary quadilateral according to given values, where (x1, y1) are top-left cordinates, (x2, y2) are top-right cordinates, (x3, y3) are bottom-right cordinates, (x4, y4) are bottom-left cordinates", | ||
"url": "https://github.com/publiclab/image-sequencer/tree/master/MODULES.md", | ||
"inputs": { | ||
"x1": { | ||
"type": "integer", | ||
"desc": "Cordinate x1 of quadilateral", | ||
"default": 100 | ||
}, | ||
"y1": { | ||
"type": "integer", | ||
"desc": "Cordinate y1 of quadilateral", | ||
"default": 100 | ||
}, | ||
"x2": { | ||
"type": "integer", | ||
"desc": "Cordinate x2 of quadilateral", | ||
"default": 200 | ||
}, | ||
"y2": { | ||
"type": "integer", | ||
"desc": "Cordinate y2 of quadilateral", | ||
"default": 100 | ||
}, | ||
"x3": { | ||
"type": "integer", | ||
"desc": "Cordinate x3 of quadilateral", | ||
"default": 100 | ||
}, | ||
"y3": { | ||
"type": "integer", | ||
"desc": "Cordinate y3 of quadilateral", | ||
"default": 200 | ||
}, | ||
"x4": { | ||
"type": "integer", | ||
"desc": "Cordinate x4 of quadilateral", | ||
"default": 200 | ||
}, | ||
"y4": { | ||
"type": "integer", | ||
"desc": "Cordinate y4 of quadilateral", | ||
"default": 200 | ||
} | ||
}, | ||
"docs-link": "https://github.com/publiclab/image-sequencer/blob/main/docs/MODULES.md" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need these? I remember taking out the progress code..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't exactly know, should I remove this?