Idea for an image copy, paste and erase lua script.

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
JeremyLavine
Posts: 14
Joined: Mon Feb 24, 2014 7:32 pm

Idea for an image copy, paste and erase lua script.

Post by JeremyLavine »

Lets say you're adding lasers to an image sequence, but the lasers need to pass behind an object in the image. Presently what I do is I open the image within Photoshop, copy the area that needs to be placed on top of the laser, erase areas of the copied image to transparent, save, then load that image into AS to be placed over the frame of it's parent image to cover the laser. It would be great if all this could be done within AS.

*Select the area of the image to be copied.
*Copying the image, the script will automatically know the coordinates where to replace it after assigning an image layer to it, covering the object that needs to pass behind it.
*An eraser function to manually erase portions of the copied image.

A starting point could be this Gimp lua script that takes an image from AS and loads it into Photoshop:
http://lostmarble.com/forum/viewtopic.php?t=12483

I wouldn't know how to rework the Gimp script for the above ideas. I already tried tweaking it unsuccessfully to work with Photoshop:
http://lostmarble.com/forum/viewtopic.php?f=12&t=25528

So, is there anyone that would like to take a stab at this idea, building this lua script?

My son's Lego Star Wars movie is taking me forever to complete! :D
Last edited by JeremyLavine on Tue Feb 25, 2014 8:48 pm, edited 1 time in total.
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Re: Idea for an image copy, paste and erase lua script.

Post by heyvern »

Hmm...

The only way to "erase" an image layer in Anime Studio is by creating a mask. Image pixels don't "exist" inside Anime Studio and can't be edited directly. They are referenced to an external file so there is no way to edit them in Anime Studio. There is no raster functions in Anime Studio. "True" erasing would have to be done in an image editor, or done using masking in Anime Studio. If ASP masking is used, this would have to be done by hand, determining the areas to mask and drawing shapes by hand.

There really wouldn't be any way to tell an image editor where and how to "erase" portions of an image based on input from Anime Studio.

I think the best way to do this is what you are already doing by opening in Photoshop or an image editor and editing by hand. To save time you could plan ahead and determine how many "layers" the image needs, to create the layering effect you need. Then importing the layered PSD document into Anime Studio. By doing it this way you can do all of your image editing first which can save effort and bouncing back and forth and updating the Anime Studio file.

For example if you know you plan to have "layers" in an image for "lasers" to pass in front and behind objects, then separate and create those layers in photoshop first. Import the PSD as individual layers into Anime Studio. This is the most efficient way to achieve what you want.

Another option would be to simply duplicate the same image layer in Anime Studio and use ASP masking in a group layer and draw vector shapes in Anime Studio around the areas in the image layer that should be separate layers.

All of these options and choices are simply duplicates of what is available with PSD layer support in Anime Studio. Masking portions of a duplicated image layer would probably take as much time or more, than simply separating the layers in Photoshop or Gimp.

This is just my opinion based on my experience and knowledge. Someone else may have a better solution.
User avatar
JeremyLavine
Posts: 14
Joined: Mon Feb 24, 2014 7:32 pm

Re: Idea for an image copy, paste and erase lua script.

Post by JeremyLavine »

heyvern, how about copying a select area of an image within AS, then export it to Photoshop. While AS exports to Photoshop, it remembers the coordinates of where the image was copied and creates a layer exactly the same size of the copied image and places it over that area. Once the image is ready in Photoshop, you could import the image to that new layer which is exactly where you want it to be.

My biggest problem is resizing and aligning the image manually exactly over where I want it, to match the parent image in the background. It takes time and it's always off a bit. If AS could record the coordinates and size of the copied image to create a layer at the same size of where it was copied so I could import an image into it, it would save me hours.

Just thought of something. Is there a script to control the mouse cursor by use of the keyboard arrow keys? That would solve one problem, but I would still have to resize.
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Re: Idea for an image copy, paste and erase lua script.

Post by heyvern »

You don't need to do any any of that really. You should never have to "align" or position an image cut out of the background to line it up if it came from the same image and has the exact same dimensions. Just cut it out in photoshop but keep the same dimensions. It will import in the exact same positions. I do this all the time with Photoshop and Anime Studio. Never even considered needing this type of scripted connection.

If you open the image in Photoshop and cut out different layers, keeping the entire PSD file as one file with the layers in place, when you import the PSD into Anime Studio, all the layers are kept aligned perfectly and on separate layers. No aligning or repositioning is required.

If you don't want to use PSD import/linking, you can simply save out each layer from a PSD with transparency (png) but keep each layer the same dimensions. There are scripts for Photoshop that export layers as files. There shouldn't be any need to adjust or align image layers the way you describe. When each layer is imported into Anime Studio they are all the same size and same origin and position and will line up perfectly.

Maybe I don't understand exactly what you are trying to do. Maybe it would help to see some kind of work flow or the process you are using to get what you need. It seems to me that it's possible you are making it harder than it needs to be.

To be honest, trying to convert Anime Studio screen mouse locations and bounding areas is... well... it's going to be hard as heck, and as far as I can tell from what you are trying to do is not even needed. There are much more simple, straight forward ways to do this that it just isn't worth the effort.

One issue is that Anime Studio uses it's own mouse position coordinates which would have to be converted to PSD. Also, the mouse positions in Anime Studio are RESOLUTION INDEPENDENT, the positions are not based on pixels at all but on Anime Studio's internal position grid. A point at -20 is the same no matter what the dimensions of the project are. There isn't a clear conversion of the location to pixel values.

There is a mouse location to location in Anime Studio scripting but it's used within ASP to transfer a mouse position to a point location. For example a point location is a general position within ASP's grid. The mouse position is based on where you click on the screen. That info would have to be converted and sent to Photoshop and used within Photoshop scripting to draw a layer and copy out a piece of an image and... and... <sigh>.... this would get horrendously complicated and makes me sleepy just thinking about it... and as I said I can't think of a good reason to go to all that trouble when it's so easy to simply do this with photoshop and import the layers already lined up. There is no need to do this since you can keep layers lined up by exporting them from photoshop correctly.

I often create horrendously complicated scripts that also make me sleepy... but the result is something that takes truckloads of extra repetitive effort. I would only consider it if there is no other solution and the return on investment of the work to create the script is more than doing it another way. In my mind doing this with photoshop takes minutes and a scripted solution would hardly save very much time at all.

I keep coming back to the same thing when I run this idea through my head... you end up still having to open photoshop and editing or running stuff in that program... plus on top of that all the complicated scripting involved. Sometimes just "doing it" is easier than trying to script it. The trick is finding a better way to do it without the scripting overhead.

I understand what you would like to do, and can even appreciate why this could be helpful. The problem I have is that doing this "the regular way" without scripting is not much different or time consuming than trying to script it.

This is just my take on the issue you have. I have done a ton of Anime Studio scripting and am pretty familiar with what is possible and relatively easy to do. Connecting Anime Studio to Photoshop in this way is not going to be easy and the benefits don't make the effort worthwhile in my opinion.
User avatar
JeremyLavine
Posts: 14
Joined: Mon Feb 24, 2014 7:32 pm

Re: Idea for an image copy, paste and erase lua script.

Post by JeremyLavine »

I've experimented a little more with Anime Studio, and it does correctly size the edited selected area of an image from Photoshop, but the location of it is way off when it's imported since it's not a copy of the entire image but a small area of it.

I'm gonna try to code this in lua, but it might take a while since I have other things going on. Instead of copying a section of an image, I'll just copy the whole image and resave it to disk, then write the location of it in a text file, then create a layer and load it there. I created an app in VB.net that when started by lua would read this text file for the location of the image and open it in Photoshop. It would work with every image entry in this file. Nothing will be copied or cut out from this image, I'll just use the whole thing and erase areas in PS where needed.
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Re: Idea for an image copy, paste and erase lua script.

Post by heyvern »

JeremyLavine wrote:I've experimented a little more with Anime Studio, and it does correctly size the edited selected area of an image from Photoshop, but the location of it is way off when it's imported since it's not a copy of the entire image but a small area of it.
Not sure what you mean? Are you "cropping" the image after clipping it? Are you changing the origin? If you have an image layer in Anime Studio, open that exact image in photoshop, cut a chunk out creating a new layer, then save that new photoshop layer with the exact same dimensions and layer offset it will import into Anime Studio exactly lined up. Duplicate the image layer in Anime Studio and replace the image source with the new image. I still think you are making this ten times harder than it has to be.
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Re: Idea for an image copy, paste and erase lua script.

Post by heyvern »

Dude!

I was just downloading all the new Adobe CC applications (I have the creative cloud suite).

I noticed that there is an "ExtendScript Toolkit CC". This is like a scripting language kit for the Adobe applications. You can use it to build stuff to control Adobe applications. Don't know if you have the CC version of Photoshop. I didn't see anything like this for CS6 though.

This may help you create what you need for your scripting solution with Anime Studio. You could possibly create an Extenscript gizmo and then send stuff from Anime Studio to that and it would run photoshop and do the stuff you need.

The tricky part I see is going from Photoshop back to Anime Studio. I don't think you can update an open Anime Studio document from an external script. Usually a lua script does stuff to the open document. In your case you need to launch Photoshop, do stuff there, save a file, then load it into Anime Studio. I am not sure that Anime Studio can do stuff from "the outside" so to speak. You may need a "2 part" script. Run the first part to create the new image layer, then run part two to load the new layer.

Anyway... it's an idea.
User avatar
JeremyLavine
Posts: 14
Joined: Mon Feb 24, 2014 7:32 pm

Re: Idea for an image copy, paste and erase lua script.

Post by JeremyLavine »

heyvern wrote:
JeremyLavine wrote:I've experimented a little more with Anime Studio, and it does correctly size the edited selected area of an image from Photoshop, but the location of it is way off when it's imported since it's not a copy of the entire image but a small area of it.
Not sure what you mean? Are you "cropping" the image after clipping it? Are you changing the origin? If you have an image layer in Anime Studio, open that exact image in photoshop, cut a chunk out creating a new layer, then save that new photoshop layer with the exact same dimensions and layer offset it will import into Anime Studio exactly lined up. Duplicate the image layer in Anime Studio and replace the image source with the new image. I still think you are making this ten times harder than it has to be.
Before I was selecting an area of the image within Photoshop, copying or cutting it out to edit. Since it was a small area of the orginal image, that's why it wouldn't align in Anime Studio. What works from what I started doing yesterday, as you wrote above, is using the whole image, erasing the areas where needed, then importing it into an image layer that overlays the unedited copy. Solves the problem of having to align the image because like you said, Anime Studio does it for you if it's the same size as the orginal.

Still gonna create the scripts to speed this process along. The VB portion, when launched by lua, will automatically find the available image editors and ask you once which one you prefer, save that data within a log, then it would always open that image editor using the same lua script that provides the image location. Also gonna see if I could do this all in lua since synthsin75 gave me the link to his lua script that starts Photoshop:
viewtopic.php?f=12&t=25528
When complete I'll post the code here.

Anime Studio auto-updates it's image layers after you save from whatever image editor you use. No need to reload the image. :D

I'm using Photoshop Elements 5, so I probably can't use the Toolkit you mentioned, but thanks for the info! The old version of PS has met my needs, but my VB script will work with all versions of Photoshop, to include Gimp, Paintshop and others. Not sure if I have the time to code that in lua, but if I could get lua to do the other things I mentioned in a previous post, that would be enough since VB would do the rest.
Last edited by JeremyLavine on Wed Feb 26, 2014 2:45 pm, edited 2 times in total.
User avatar
hayasidist
Posts: 3831
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Idea for an image copy, paste and erase lua script.

Post by hayasidist »

Not sure if this will help but ... Would I be right in thinking that you have an image sequence from stop-action and you want to separate fg and bg of that so you can add AS generated laser shots?

If that's the question then read on. If not skip the next paragraph.

IMO, the easiest way to deal with this is in a compositor such as premiere. Import the sequence as a video. Import the lasers next layer up. Create a travelling matte (from the original video and/or use garbage matte and/or chroma key) to mask in the fg and then layer the original video on top of that.

Or maybe it's just a static image. In which case, IMO, the easy way is to mask the lasers in AS, which I think Vern has already suggested.
User avatar
JeremyLavine
Posts: 14
Joined: Mon Feb 24, 2014 7:32 pm

Re: Idea for an image copy, paste and erase lua script.

Post by JeremyLavine »

Hi hayasidist,

Yeah, I should've mentioned it's a stop action image sequence, but synthsin75's script to launch Photoshop has helped me out. Once I have the image in Photoshop, I place it on top of a transparent layer, erase where needed, then I save it as a png and load it into another image layer overlaying the orginal. Takes care of the issue of having the laser passing behind a lego character.

viewtopic.php?f=12&t=25532
User avatar
hayasidist
Posts: 3831
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Idea for an image copy, paste and erase lua script.

Post by hayasidist »

Sounds as though you've got it sorted! But I hope you don't have to do that on every frame... But ...

Might help speed things up in PS: if you make a clipping mask you won't need to erase parts of an image - you can 'un-delete' bits by editing the clipping mask. You can also soft-edge the mask if that makes the result visually better. And if/as the frames in the sequence are similar, you can share the clip mask across frames. But I still think that the Premiere and travelling matte route is quicker and cleaner - I do this quite a bit in mixed live/animated action.
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Re: Idea for an image copy, paste and erase lua script.

Post by heyvern »

Based on what you are describing...

What you are doing is masking out the laser. It almost seems to me that it would be faster/easier to MASK THE LASER using standard Anime Studio masking and not create the layered object images in Photoshop.

Follow along for a moment:

You have one image layer with various multi-level objects you want the laser to go in front of and behind. In your workflow you are cutting out the image shapes to move above and below the laser blasts. This requires drawing around those shapes, creating a new layer or image in photoshop and loading it back into Anime Studio.

The same process could be done with masking in Anime Studio.

Put the laser inside a group layer. Set the mask of the laser group to "Show all". Create a vector mask at the bottom of the group. Draw vector shapes around the elements of the image layer to hide the laser. It's almost the same effort as doing this in Photoshop, you still are drawing shapes to match the objects in the image layer, but you can do it all in Anime Studio with out needing a bunch of extra image layers to hide the laser.
User avatar
hayasidist
Posts: 3831
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Idea for an image copy, paste and erase lua script.

Post by hayasidist »

hayasidist wrote:?.. IMO, the easy way is to mask the lasers in AS, which I think Vern has already suggested.
Agreeing (again) with Vern, if your image sequence doesn't have a lot of movement that needs to go in front of lasers, use masking in AS!
User avatar
JeremyLavine
Posts: 14
Joined: Mon Feb 24, 2014 7:32 pm

Re: Idea for an image copy, paste and erase lua script.

Post by JeremyLavine »

Masking did the trick! The lasers now look like they're passing behind objects within my son's stop motion sequence.

I've learned masking in Anime Studio from these YouTube videos:
http://www.youtube.com/watch?v=b29hvORO6SY


http://www.youtube.com/watch?v=VjdB0AiVTac

I'm gonna still play with lua scripting, but now I don't have to worry about creating what I had in mind before.

hayasidist, heyvern, thanks for bringing this great AS feature to my attention!
Post Reply