Image-sequencer: ability to set step options via string command syntax: "invert,threshold:{level:50}"

Created on 2 Oct 2017  ·  29Comments  ·  Source: publiclab/image-sequencer

The ability to record both steps and settings in a string could be useful for browser work, for saving sequences in localStorage, in a key/value database on server or client side, and for REST based processing, so I think it's worth considering for all those reasons.

Building on #91, the URL format:

/examples/#steps=green-channel,crop

Could have additional options set with:

/examples/#steps=green-channel,crop[w:50%|h:30%]

Is this an appropriate way to encode steps? crop[w:50%|h:30%] or is there an easier or more straightforward way?

Update

Considering after #203, using parentheses:

?steps=invert,green-channel,threshold(50) or for more complex parameters:

?steps=ndvi('blue'),lens({x:25,y:15})

OR simpler:

?steps=ndvi('blue'),lens(x:25,y:15)

Or even full JSON, although it's less compact:

?steps={ndvi:'blue'},{lens:{x:25,y:15}} --

we could potentially have a "simple" syntax that's optimized for use in URLs, and a "full" syntax that's actually JSON.

enhancement help wanted important new-feature

Most helpful comment

@jywarren we have it already!!😁

All 29 comments

@tech4GT suggests, and I agree!:

maybe we can have an option to store default value of options in the json itself and if the user does not give any values when the module is used it can be used as sort of a fallback case or default values for the meta-module, what say?

@jywarren On the browser side once we implement this maybe we can have a save to local storage in the sharing options which will ask the user for a name and the meta-module will be saved with the settings user has currently applied, what say?
PS just thinking how we would make the UI/UX for this so that it feels natural

See comment here: https://github.com/publiclab/image-sequencer/pull/203#issuecomment-381692525

I think i'm really thinking of a way to do something like sequencer.toString() - a general purpose way to string-encode a sequence, so it could be used in any of these places. We don't even need to DO them all just yet, but if we make good architectural choices at this point we are in a good place for the future.

So in summary, we should run the URL hash through a new sequencer.import() type command, and implement options-setting as part of the standard "command string" syntax which this import() reads. Changing title to match this!

Here's the current implementation of importStepsFromUrlHash() which could be generalized into a sequencer.importSteps(string):

https://github.com/publiclab/image-sequencer/blob/1de72d7325cfa8ea1ab38ba8f5f5b1c75e31195f/examples/lib/defaultHtmlSequencerUi.js#L12-L23

Hope that helps!!!

@jywarren thanks😀

Once we get to this, we'll want to have a number of tests which show how it can be used. For example, let's have a test which begins with just one module, then use a string like invert,importImage(url:"dir/example.jpg"),ndvi and then confirm that the sequencer has those steps invert, importImage, ndvi - and that importImage has correctly received the URL. We could show tests for each type of parameter too, like string parameters, integers, and even functions.

The tests can act as a kind of guide for how to use the feature -- and when we add documentation (which could also be part of the PR), we can link people to the corresponding tests to demonstrate how they work in real code. It may be worthwhile to break out the import and toString tests into their own test file, maybe called importExport.js or something?

@jywarren Got it!! This makes total sense!!

Should we make a pure-json variant or hold off on this for now?

@jywarren I think after doing this only one function makes sense sequencer.importStepsfromJSON() since after importing the steps sequencer.toString() can be used to produce the string.

this function can basically serve as a wrapper around adding multiple steps defined in an array with their options
This will also complete the architecture we originally decided

but why not importStepsFromString()? I'm thinking about if we take the
entire URL hash and pass it to a single function, you know?

On Sun, Jun 3, 2018 at 10:47 AM, Varun Gupta notifications@github.com
wrote:

this function can basically serve as a wrapper around adding multiple
steps defined in an array with their options
This will also complete the architecture we originally decided


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/image-sequencer/issues/127#issuecomment-394175035,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABfJznD0iosDHLZ2sZkdEyzeKfksxtPks5t5BMKgaJpZM4Pqk6F
.

@jywarren I don't understand, do we want to stringify JSON?

I mean the current ImportStepsfromString() imports these steps right?

oh, wait -- let me see. the API has changed a lot in the past week!

@jywarren I'll list it so we have a sequencer.toString() which takes the currents steps and outputs them as a string, then we have a sequencer.importStepsFromStringtoJson(string) which takes a stringified sequence and returns the steps as json.

Oh, wait - no that's ok, no need for importStepsFromStringtoJson - i just don't see a sequencer.importStepsfromString() -- going from, say, a URL hash directly to steps. It's exactly the function the excerpted demo code does. The code we have already in the core is only to JSON, not to instantiated steps. I just want one more simple function that gets you all the way in a single function -- how does that sound?

Yikes sorry too many function names flying around. Edited the above to mean importStepsFromString()

@jywarren that is a great idea!!
what we can do is that we can have a importString function which internally calls the sequencer.toJSON function(basicall we change the current importStepsfromStringtoJson to sequencer.json)

@jywarren I got this!! Don't worry I have a pretty good idea of what we need now

I 'll do some refactoring and then post all the final function names and what they do here

OK! One thing that may help is to move all of the import/export functions into a separate source file called io.js or something? Our main source file ImageSequencer.js is getting a bit long, and we have a whole set of inter-related functions we could put in their own file, right?

@jywarren Good idea!! I'll do that too!!

But isn't it very late there? No need to do this now, just thinking about next steps!!!

working on this now!!

@jywarren No problem this will only take a couple of minutes

This is done now closing!!

Did we want to break out any follow up steps like a pure json style string
type? Or anything else?

Esp not including settings if they match the defaults? Or do we have one
open for that already?

Great!!!!!

On Fri, Jun 8, 2018, 2:04 PM Varun Gupta notifications@github.com wrote:

This is done now closing!!


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/image-sequencer/issues/127#issuecomment-395841444,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABfJ3r5uwHg1kI8bAOpRX_cKx_CKq60ks5t6rx7gaJpZM4Pqk6F
.

@jywarren we have it already!!😁

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vaibhavmatta picture vaibhavmatta  ·  4Comments

jywarren picture jywarren  ·  5Comments

jywarren picture jywarren  ·  5Comments

jywarren picture jywarren  ·  3Comments

sashadev-sky picture sashadev-sky  ·  3Comments