10 Replies Latest reply on Jul 29, 2015 2:06 AM by pb4891

    change white color to grey

    pb4891 Level 1

      //opening a file

       

       

      var fileRef = File("D:/EL20427_02.jpg") ;

      var docRef = app.open(fileRef) ;

       

      var docWidth = docRef.width;

      var docHeight = docRef.height;

      var xPos = 0;

      var yPos = 0;

      // Create a color to be used with the fill command

      var colorRef = new SolidColor ;

      colorRef.rgb.red = 233 ;

      colorRef.rgb.green = 233 ;

      colorRef.rgb.blue = 233;

      var sampler =docRef.colorSamplers.add([0, 0]);

      for(xPos = 0; xPos <= docWidth; xPos++)

      {

      for(yPos = 0; yPos <= docHeight; yPos++)

      {

       

      sampler.move([xPos, yPos]);

              var color = sampler.color;

          if (color.rgb.hexValue == "FFFFFF") {

              var region = [

                  [xPos, yPos],

                  [xPos + 1, yPos],

                  [xPos + 1, yPos + 1],

                  [xPos, yPos + 1],

                  [xPos, yPos]

              ];

       

       

      docRef.selection.select(region);

              docRef.selection.fill(colorRef);

       

      }

      }

      }

       

      jpgFile = new File(""D:/temp_EL20427_02.jpg");

      jpgSaveOptions = new JPEGSaveOptions() ;

      jpgSaveOptions.embedColorProfile = true;

      jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE ;

      jpgSaveOptions.matte = MatteType.NONE ;

      jpgSaveOptions.quality = 1 ;

      app.activeDocument.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE);

        • 1. Re: change white color to grey
          c.pfaffenbichler Level 9

          Is there a problem (apart from the time the Script might take or the Color Sampler position) or do you have a question?

          • 2. Re: change white color to grey
            pb4891 Level 1

            It is taking a lot of time and the output image is not correct ( it is showing small valid image on top left side )

            • 3. Re: change white color to grey
              c.pfaffenbichler Level 9

              Well, your approach does seem problematic, measuring each pixel individually via a Script is generally not a great idea.

              Have you considered using Select > Color Range (the AM code resulting from that) instead?

               

              it is showing small valid image on top left side

              Could you post a screenshot to illustrate?

              This might be the result of the Color Picker position not being in the centre of a pixel but on a conner.

              • 4. Re: change white color to grey
                dominique filiol Level 2

                Bonjour

                 

                Ce script ?

                 

                [code]

                //Recherche de crame

                //changeBlancGris.jsx

                 

                var coulWhite = new SolidColor();

                coulWhite.rgb["hexValue"] = "ffffff";

                 

                var coulGrey = new SolidColor();

                coulGrey.rgb["hexValue"] = "e9e9e9"; //R=233 V=233 B=233

                 

                selectColorRange(coulWhite);

                 

                //changer le blanc en gris

                activeDocument.selection.fill(coulGrey);

                activeDocument.selection.deselect();

                 

                function selectColorRange(scObj)

                {

                    var desc = new ActionDescriptor();

                    desc.putInteger( charIDToTypeID( "Fzns" ), 0 );

                    var cDesc = new ActionDescriptor();

                    cDesc.putDouble( charIDToTypeID( "Rd  " ), scObj.rgb.red);

                    cDesc.putDouble( charIDToTypeID( "Grn " ), scObj.rgb.green);

                    cDesc.putDouble( charIDToTypeID( "Bl  " ), scObj.rgb.blue);

                    desc.putObject( charIDToTypeID( "Mnm " ), charIDToTypeID( "RGBC" ), cDesc );

                    desc.putObject( charIDToTypeID( "Mxm " ), charIDToTypeID( "RGBC" ), cDesc );

                    executeAction( charIDToTypeID( "ClrR" ), desc, DialogModes.NO );

                }

                 

                [/code]

                • 5. Re: change white color to grey
                  pixxxel schubser MVP & Adobe Community Professional

                  pb4891,

                  now I'm confused.

                   

                  Does this mean the same problem like your other thread: how o change background color of an image using script?

                  • 6. Re: change white color to grey
                    pb4891 Level 1

                    Thank you so much. The script is working correctly. Is there any way to select color with some tolerance. +-5%. instead of selecting exact white?

                    • 7. Re: change white color to grey
                      dominique filiol Level 2

                      Bonjour

                       

                      Peut etre comme ceci :

                       

                      //Recherche de crame

                      //changeBlancPipetteLAB.jsx

                       

                       

                      //Le blanc LAB :

                       

                      var L=100;

                      var A=0;

                      var B=0;

                       

                      var tolerance = 5 ;  //pourcentage de blanc LAB

                       

                      selectBlancLab()

                       

                      var coulGrey = new SolidColor();

                      coulGrey.rgb["hexValue"] = "e9e9e9"; //R=233 V=233 B=233

                       

                      //changer le blanc en gris

                      activeDocument.selection.fill(coulGrey);

                      activeDocument.selection.deselect();

                       

                      function selectBlancLab()

                      {

                          //selection plage couleur pipette sur BLANC( FFFFF ou LAB 100 0 0 )

                          var idClrR = charIDToTypeID( "ClrR" );

                          var desc29 = new ActionDescriptor();

                          var idFzns = charIDToTypeID( "Fzns" );

                          desc29.putInteger( idFzns, tolerance ); //15 );

                          var idMnm = charIDToTypeID( "Mnm " );

                          var desc30 = new ActionDescriptor();

                          var idLmnc = charIDToTypeID( "Lmnc" );

                          desc30.putDouble( idLmnc, L );//99.910000 );

                          var idA = charIDToTypeID( "A   " );

                          desc30.putDouble( idA, A); //-0.370000 );

                          var idB = charIDToTypeID( "B   " );

                          desc30.putDouble( idB, B); //-0.150000 );

                          var idLbCl = charIDToTypeID( "LbCl" );

                          desc29.putObject( idMnm, idLbCl, desc30 );

                          var idMxm = charIDToTypeID( "Mxm " );

                          var desc31 = new ActionDescriptor();

                          var idLmnc = charIDToTypeID( "Lmnc" );

                          desc31.putDouble( idLmnc, L); //99.910000 );

                          var idA = charIDToTypeID( "A   " );

                          desc31.putDouble( idA, A ); //-0.370000 );

                          var idB = charIDToTypeID( "B   " );

                          desc31.putDouble( idB, B );   //-0.150000 );

                          var idLbCl = charIDToTypeID( "LbCl" );

                          desc29.putObject( idMxm, idLbCl, desc31 );

                          var idcolorModel = stringIDToTypeID( "colorModel" );

                          desc29.putInteger( idcolorModel, 0 );

                          executeAction( idClrR, desc29, DialogModes.NO );

                      }   

                       

                      • 8. Re: change white color to grey
                        pb4891 Level 1

                        The script is working exactly

                        • 9. Re: change white color to grey
                          pb4891 Level 1

                          Is it possible to pick color from 0,0 pixel (at the starting of document) then select that colored part with 5% allowed tolerance?

                          • 10. Re: change white color to grey
                            pb4891 Level 1

                            First I want to re size the canvas, then pick color from starting point, select that colored part with some tolerance,, change selected part's color to white,,, but color is not changing, can u help with it?

                             

                             

                             

                             

                             

                            var rulerUnit = app.preferences.rulerUnits;

                            app.preferences.rulerUnits = Units.PIXELS;

                             

                             

                             

                             

                            // call the source document

                            var srcDoc = app.activeDocument;

                             

                             

                             

                             

                            // get original width and height

                            var imageW = srcDoc.width.value;

                            var imageH = srcDoc.height.value;

                             

                             

                             

                             

                            imageW= imageW-1000;

                            imageH= imageH-1000;

                             

                             

                            app.activeDocument.resizeCanvas(imageW, imageH,AnchorPosition.MIDDLECENTER);

                             

                             

                            app.activeDocument.colorSamplers.removeAll();

                            var pixelLoc = [UnitValue(0) , UnitValue(0)];

                            var myColorSampler = app.activeDocument.colorSamplers.add(pixelLoc);

                            var myColor = myColorSampler.color;

                             

                             

                             

                             

                             

                            var L=myColor.lab.l;

                            var A=myColor.lab.a;

                            var B=myColor.lab.b;

                             

                             

                            var tolerance = 5 ; 

                             

                            selectBlancLab()

                             

                             

                            var coulWhite = new SolidColor();

                            coulWhite.rgb["hexValue"] = "ffffff";

                            activeDocument.selection.fill(coulWhite);

                            activeDocument.selection.deselect();

                             

                            function selectBlancLab()

                            {

                             

                                var idClrR = charIDToTypeID( "ClrR" );

                                var desc29 = new ActionDescriptor();

                                var idFzns = charIDToTypeID( "Fzns" );

                                desc29.putInteger( idFzns, tolerance ); //15 );

                                var idMnm = charIDToTypeID( "Mnm " );

                                var desc30 = new ActionDescriptor();

                                var idLmnc = charIDToTypeID( "Lmnc" );

                                desc30.putDouble( idLmnc, L );//99.910000 );

                                var idA = charIDToTypeID( "A   " );

                                desc30.putDouble( idA, A); //-0.370000 );

                                var idB = charIDToTypeID( "B   " );

                                desc30.putDouble( idB, B); //-0.150000 );

                                var idLbCl = charIDToTypeID( "LbCl" );

                                desc29.putObject( idMnm, idLbCl, desc30 );

                                var idMxm = charIDToTypeID( "Mxm " );

                                var desc31 = new ActionDescriptor();

                                var idLmnc = charIDToTypeID( "Lmnc" );

                                desc31.putDouble( idLmnc, L); //99.910000 );

                                var idA = charIDToTypeID( "A   " );

                                desc31.putDouble( idA, A ); //-0.370000 );

                                var idB = charIDToTypeID( "B   " );

                                desc31.putDouble( idB, B );   //-0.150000 );

                                var idLbCl = charIDToTypeID( "LbCl" );

                                desc29.putObject( idMxm, idLbCl, desc31 );

                                var idcolorModel = stringIDToTypeID( "colorModel" );

                                desc29.putInteger( idcolorModel, 0 );

                                executeAction( idClrR, desc29, DialogModes.NO );

                            }