Photoshop: Quick way to make multiple layers from inversely selected objects.

  • 2
  • Idea
  • Updated 7 years ago
  • (Edited)
Imagine a single image with a solid color background with a lot of smaller icons or images around it. I Want to magic wand the solid color background - select the inverse from there (meaning all the little icons and smaller objects are selected) and then this new feature lets me make layers via cut or copy of each "whole selection". So if its a giant image if a deck of cards laid out on a purple background with space between them for example, select inverse from the background (easy to do now) and then magic happens and I get 52 layers, one of each of the cards, make sense?
Photo of Noah R

Noah R

  • 6 Posts
  • 0 Reply Likes

Posted 7 years ago

  • 2
Photo of christoph pfaffenbichler

christoph pfaffenbichler, Champion

  • 1199 Posts
  • 159 Reply Likes
Maybe you should check in the Photoshop Scripting Forum
http://forums.adobe.com/community/pho...

At least once the task has been tackled with a Script that used converting the selection to a working path the subPathItems of which were then employed to perform the separation of the non-contiguous selected regions.

Edit: Can’t find a thread that features the code; still, if you ask there you might get some help with the issue.
Photo of Noah R

Noah R

  • 6 Posts
  • 0 Reply Likes
I walked around there for a while and saw a couple posts that were helpful before posting here, but I am thinking more of a internal function of photoshop rather than it being a script. Making it internalized would be useful as it can be integrated nicely into the other tools as sub-functions. Like any select or any type of wand. Same with brushes, you can do it all in one function - have starting image, select inverse use your brush to make any changes accordingly, then use said function that creates the individual layers along with sublayers of the brush edits and what not. I think for now, scripting is going to have to be the solution for a quick fix, but it seems (logically) to not be so hard to incorperate into the program itself. All depends on the magic spaghetti they have cooking up in the background. :)
Photo of christoph pfaffenbichler

christoph pfaffenbichler, Champion

  • 1197 Posts
  • 158 Reply Likes
True, Scripting is a work-around here and an integrated solution could probably offer much higher ease of use and speed.
Still, if you want to try a Script for that let me know.
Photo of Noah R

Noah R

  • 6 Posts
  • 0 Reply Likes
Yep, I think thats the route for now. I think I will give a go at it. Been a while though. If you want to help, I have a test image I can send your way so you can understand what I am trying to achieve.
Photo of christoph pfaffenbichler

christoph pfaffenbichler, Champion

  • 1197 Posts
  • 158 Reply Likes
I could send you a Script that I hope might be of use – are you present on forums.adobe.com and if so, what’s your name over there?
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 765 Reply Likes
Ok, the description is a bit confused -- but it sounds like you want a way to turn isolated objects on a background into individual layers. Kind of like Crop and Straighten, but applied to more objects than it usually handles?

Yes, a script should be able to do this for the time being.
Photo of Noah R

Noah R

  • 6 Posts
  • 0 Reply Likes
The best way to is to show you this image.

Imagine that image not in a grid format, and each 'square' with some of the background purple between all sides. Then you magic wand select the purple, then select the inverse (right click - select inverse). Now you have all of the squares selected. This feature then allows you make layers via cut or copy for each 'whole' selection, meaning each square becomes its own layer rather than one layer with all the squares on it. Think of it like puzzle pieces and each piece is its own layer which can be moved independent of any other piece. Right now, other than scripting it, I am using the magic wand/quick selection and pulling out each piece one at a time and making a layer. Make sense?

Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 765 Reply Likes
OK, so that doesn't match your request or my guess. Here you have a grid of items you'd like separated -- even easier for a script. But not all of the items are the same size (some span multiple grid points). And most of the objects in your example don't have color between them. You can probably separate based on the grid, then recombine the objects/layers that should go together.
Photo of Noah R

Noah R

  • 6 Posts
  • 0 Reply Likes
This is probably a better example then. The feature is not dependent on image source or size. Take this image, select the purple, do inverse selection then use the feature to create layers for each green area by itself. So this image would give you 13 layers.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 731 Reply Likes
That is closer to what I first described. It shouldn't need a selection to start, just some specification of the "background" color (maybe like the trim command).
Photo of Noah R

Noah R

  • 6 Posts
  • 0 Reply Likes
now imagine a 500 piece puzzle and each piece is one of the green items above. Make it work with something like that (and more). The pieces are not just solid color shapes, this is an example for the basic jist. Right now, I would use the magic wand and quick select to isolate each piece one at a time and then make a new layer via copy or cut. I am looking for an all in one step.
Photo of Paul Riggott

Paul Riggott

  • 346 Posts
  • 131 Reply Likes
You could try running this code, it requires that all the object are selected before running the code.

Arrrrrrrrrrr Even using pre and /pre the code is not shown! How do you add code on this forum?
http://www.scriptsrus.talktalk.net/do...
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 765 Reply Likes
Not the most accurate way to get the job done (since selection->path and path->selection will be lossy), but an interesting way to break it down into shapes using subpaths.
Photo of David Jensen

David Jensen

  • 131 Posts
  • 46 Reply Likes
If you have a 1-bit selection, you can do a lossless conversion to a path,
Just scale the image to 200% using nearest neighbor, then use the minimum radius on the path conversion, then scale back to 50%

I would like a built in way to split non-contiguous objects into separate layers, though.
Photo of christoph pfaffenbichler

christoph pfaffenbichler, Champion

  • 1199 Posts
  • 159 Reply Likes
»Not the most accurate way to get the job done (since selection->path and path->selection will be lossy),«
A workaround that came to mind was expanding the selections based on the individual subPathItems and intersecting those with the original mask, but depending on the softness of the Selection this naturally still can cause problems.
Mr.Cox, do you see any better method that could be scripted?
Photo of David Jensen

David Jensen

  • 131 Posts
  • 46 Reply Likes
1. Delete the selected (background) area (magenta in the example above).
2. Invert the selection
3. Quick mask
4. threshold level 1
5. image size to 200%, using nearest neighbor
6. exit quick mask.
7. make a path from selection using a tolerance of 0.5 pixels
8. image size 50%
9. Run the script above

I made a script at some point that did all of that... not sure what I did with it