17 Replies Latest reply on Aug 8, 2015 6:24 AM by JJMack

    selecting a required part of image only in a batch process

    pb4891

      There is an image of apple on white canvas. I want to crop it in a way so that my new image will contain only required part(apple only). To explain it clearly I have drawn a black rectangle around apple and grapes. I want only what is inside rectangle. I cant give height and width to cut because I want to run that script on many images that have different different shapes (for example apple and grapes here). Should I check every pixel for color change (from white to colored) so that I can get height and width of actual part of every image or there is a better way.

       

       

      apple.jpggrapes.jpgapple (1).jpg

        • 1. Re: selecting a required part of image only in a batch process
          xbytor2 Level 4

          Magic wand at 0,0. Finding the correct tolerance will be the problem here.

          Invert the selection

          Get the selection bounds

          Crop the bounds

          • 2. Re: selecting a required part of image only in a batch process
            Chuck Uebele Adobe Community Professional & MVP

            How about using scriptlistener to record the trim command?

            • 3. Re: selecting a required part of image only in a batch process
              Chuck Uebele Adobe Community Professional & MVP

              Well the shadow throws the trim off a bit from what you want:

               

              • 4. Re: selecting a required part of image only in a batch process
                JJMack Most Valuable Participant

                I think what your writing is you have a single layer files with a subject on a white background that may have cast a shadows on the white background, That you would like to get the bounds of the subject only.  No shadow.  Your first example example is not even illustrated correctly.

                apple.jpg

                What you seem to want is this

                Capture.jpg

                Would not be easy to automate for the shadows can vary in color and the subject may also contain some of the shadows colors.

                1 person found this helpful
                • 6. Re: selecting a required part of image only in a batch process
                  JJMack Most Valuable Participant

                  This layer 0 would be easy to automate and the trim of the layer would be the green outline area.  The bottom shadow would still need to be cropped off.

                  Capture.jpg

                  • 7. Re: selecting a required part of image only in a batch process
                    pb4891 Level 1

                    I was not able to clearly explain my problem statement. Like the image I am attaching, as output I want a small image with leaf (and shadow) only, not all other part. The problem is I can not select the part I want because I want to run it for different different images consisting different different shapes. Like previously it was for apple now it is for leaf .

                     

                     

                    original.jpg

                     

                     

                     

                     

                     

                    cropped.png

                    • 8. Re: selecting a required part of image only in a batch process
                      pb4891 Level 1

                      I was not able to clearly explain my problem statement. Like the image I am attaching, as output I want a small image with leaf (and shadow) only, not all other part. The problem is I can not select the part I want because I want to run it for different different images consisting different different shapes. Like previously it was for apple now it is for leaf .

                       

                       

                       

                       

                      original.jpg

                       

                       

                       

                       

                      cropped.png

                      • 9. Re: selecting a required part of image only in a batch process
                        Chuck Uebele Adobe Community Professional & MVP

                        Again, using the trim command will get you something like this - not as tight as you sample, but close.

                         

                        • 10. Re: selecting a required part of image only in a batch process
                          JJMack Most Valuable Participant

                          If you want the shadow and the image is the leaf only not leaf and apple together then the Trim command should do what you want and crop the image to the bounds of the Leaf+Shadow..  A simple action would be the only thing required.  That Action could be batched and used to trim all your images that have single color background.  The Background color could be any color but must be one color not shades of the color like the shadow any variation from the color will not be trimmed.

                          1 person found this helpful
                          • 11. Re: selecting a required part of image only in a batch process
                            Chuck Uebele Adobe Community Professional & MVP

                            Just thinking about the issue with slight color differences. A temp adjustment layer could be added to turn the bg pure white, then use the trim command, the delete the adjustment layer. that will make the trim crop closer to the subject.

                             

                            • 12. Re: selecting a required part of image only in a batch process
                              JJMack Most Valuable Participant

                              For a white background but If over done parts of the subject and shadow would be trimmed.

                              1 person found this helpful
                              • 13. Re: selecting a required part of image only in a batch process
                                Chuck Uebele Adobe Community Professional & MVP

                                Yes, it most likely will have to be slight, but enough to get those slight shades the same and trimmed away.

                                • 14. Re: selecting a required part of image only in a batch process
                                  pb4891 Level 1

                                  temp adjustment layer could be added to turn the bg pure white,

                                  how it can b added with script?

                                  • 15. Re: selecting a required part of image only in a batch process
                                    JJMack Most Valuable Participant

                                    Did you install the scriptlistener plug-in and add a levels or curves adjustment layer to get the action manager code needed. Be sure the two steps are recorded the step that add the levels or curves adjustment layer and the step that adjust the properties if the adjustment layer.

                                     

                                    It would be easy to do in an action I feel a script would more work than needed.

                                    • 16. Re: selecting a required part of image only in a batch process
                                      Chuck Uebele Adobe Community Professional & MVP

                                      What JJ, just posted. Use the scriptlistener to record creating the adjustment layer and setting the amount that you want changed. For this I would either use levels or curves and just slightly move the highlight end point so that the very light greys/whites turn pure white. It may not take much correction.

                                       

                                      Here is what I just got using scriptlistner and levels - setting the highlight point to 238:

                                       

                                      // =======================================================
                                      //This creates the levels adjustment layer
                                      var idMk = charIDToTypeID( "Mk  " );
                                          var desc2 = new ActionDescriptor();
                                          var idnull = charIDToTypeID( "null" );
                                              var ref1 = new ActionReference();
                                              var idAdjL = charIDToTypeID( "AdjL" );
                                              ref1.putClass( idAdjL );
                                          desc2.putReference( idnull, ref1 );
                                          var idUsng = charIDToTypeID( "Usng" );
                                              var desc3 = new ActionDescriptor();
                                              var idType = charIDToTypeID( "Type" );
                                                  var desc4 = new ActionDescriptor();
                                                  var idpresetKind = stringIDToTypeID( "presetKind" );
                                                  var idpresetKindType = stringIDToTypeID( "presetKindType" );
                                                  var idpresetKindDefault = stringIDToTypeID( "presetKindDefault" );
                                                  desc4.putEnumerated( idpresetKind, idpresetKindType, idpresetKindDefault );
                                              var idLvls = charIDToTypeID( "Lvls" );
                                              desc3.putObject( idType, idLvls, desc4 );
                                          var idAdjL = charIDToTypeID( "AdjL" );
                                          desc2.putObject( idUsng, idAdjL, desc3 );
                                      executeAction( idMk, desc2, DialogModes.NO );
                                      
                                      // =======================================================
                                      //this adjust the levels
                                      var idsetd = charIDToTypeID( "setd" );
                                          var desc5 = new ActionDescriptor();
                                          var idnull = charIDToTypeID( "null" );
                                              var ref2 = new ActionReference();
                                              var idAdjL = charIDToTypeID( "AdjL" );
                                              var idOrdn = charIDToTypeID( "Ordn" );
                                              var idTrgt = charIDToTypeID( "Trgt" );
                                              ref2.putEnumerated( idAdjL, idOrdn, idTrgt );
                                          desc5.putReference( idnull, ref2 );
                                          var idT = charIDToTypeID( "T   " );
                                              var desc6 = new ActionDescriptor();
                                              var idpresetKind = stringIDToTypeID( "presetKind" );
                                              var idpresetKindType = stringIDToTypeID( "presetKindType" );
                                              var idpresetKindCustom = stringIDToTypeID( "presetKindCustom" );
                                              desc6.putEnumerated( idpresetKind, idpresetKindType, idpresetKindCustom );
                                              var idAdjs = charIDToTypeID( "Adjs" );
                                                  var list1 = new ActionList();
                                                      var desc7 = new ActionDescriptor();
                                                      var idChnl = charIDToTypeID( "Chnl" );
                                                          var ref3 = new ActionReference();
                                                          var idChnl = charIDToTypeID( "Chnl" );
                                                          var idChnl = charIDToTypeID( "Chnl" );
                                                          var idCmps = charIDToTypeID( "Cmps" );
                                                          ref3.putEnumerated( idChnl, idChnl, idCmps );
                                                      desc7.putReference( idChnl, ref3 );
                                                      var idInpt = charIDToTypeID( "Inpt" );
                                                          var list2 = new ActionList();
                                                          list2.putInteger( 0 );
                                                          list2.putInteger( 238 );//Here is the value that I changed. You can put a variable here
                                                      desc7.putList( idInpt, list2 );
                                                  var idLvlA = charIDToTypeID( "LvlA" );
                                                  list1.putObject( idLvlA, desc7 );
                                              desc6.putList( idAdjs, list1 );
                                          var idLvls = charIDToTypeID( "Lvls" );
                                          desc5.putObject( idT, idLvls, desc6 );
                                      executeAction( idsetd, desc5, DialogModes.NO );