10 Replies Latest reply: Feb 15, 2010 9:12 AM by Christian Davideck RSS

    check if all pixels are black

    Christian Davideck Community Member

      Hi folks. Does someone know a clever method to verify wether or not ALL pixels on a layer are black (0,0,0) and 100% opaque ?

       

      I guess as far as opacity is concerned, the only way is to Control-click the layer, add selection as alpha channel and verify if all pixels are white. So the same method will probably needed here, or is there a better one ?

       

      So ... how to make sure all pixels are black (or white) ? Histogram doesn't catch single pixels. And magic wand (tolerance 0) is of no help either, because I am working on very large images (a multiple of my screen's resolution) on a regular basis and (besides being time consuming) panning/zooming + eye-verification is error-prone and I would need an accurate and precise method.

       

      Any ideas?

      Many thanks for your help.

       


      (PS: It's a pity that (in CS3) there doesn't seem to be a way to make the info palette display the total amount of selected pixels. This way the solution would only be two clicks away ... That's something I should add to the wishlist ...)

        • 1. Re: check if all pixels are black
          c.pfaffenbichler Community Member

          Histogram doesn't catch single pixels.

          How do You arrive at that assumption?

          Because as far as I can tell, the Histogram does represent every pixel’s values.

           

          I suppose You might want to ask in the Photoshop Scripting Forum. 

          • 2. Re: check if all pixels are black
            Zeno Bokor CommunityMVP

            wouldn't it be easier to just fill the layer with black? if you also hold down Shift then it won't alter the transparency of the pixels.

             

            Edit: The number of pixels in a selection is displayed in the Histogram panel. For opacity you can check using Quick Mask mode, no need to make a separate alpha channel

            • 3. Re: check if all pixels are black
              c.pfaffenbichler Community Member

              True that, alt-shift-backspace fills the current layer with the foreground-color and maintains the transparency, if I’m not mistaken.

               

              Edit: That of course is no help regarding the opaque-ness-matter in the original post …

              • 4. Re: check if all pixels are black
                Zeno Bokor CommunityMVP

                as for that, Ctrl+click on the layer thumbnail, enter Quick Mask mode, with the Magic Wand set to 0 tolerance and no Anti-Alias select one of the 100% opaque pixels (black pixels while in Quick Mask), invert selection, fill with white, get out of Quick Mask and fill layer with black.

                • 5. Re: check if all pixels are black
                  c.pfaffenbichler Community Member

                  I would prefer to apply Posterize to the Selection in Quick Mask Mode to avoid having to reset the Magic Wand Tool.

                  • 6. Re: check if all pixels are black
                    Christian Davideck Community Member

                    c.pfaffenbichler wrote:

                    Histogram doesn't catch single pixels.

                    How do You arrive at that assumption?

                     

                    by TAFO (try and find out). There is rounding involved in the histogram building of course. (EDIT: I was refering to the histogram graph only. Sorry, in case you were thinking of the same solution as Zeno.)

                     

                    Zeno Bokor wrote:

                    wouldn't it be easier to just fill the layer with black?

                    The keyword here is verify not create.

                     

                    Zeno Bokor wrote:

                    The number of pixels in a selection is displayed in the Histogram panel.

                     

                    Zeno, you are a genius!! This does solve the problem.

                     

                    I always looked at the info palette, where the max. width and height of the selection is displayed.

                    Therefore the amount of selected pixels should logically be displayed there, too (all the more so as quite often width*height=amount of selected pixels )

                    So whereever they are displayed, those attributes should be displayed together.

                     

                    Thanks again, Zeno!

                    • 7. Re: check if all pixels are black
                      c.pfaffenbichler Community Member

                      There is rounding involved in the histogram building of course.

                      I wonder if You might be confusing the Histogram-display with the Histogram, which indicates the exact number of pixels of values 0 - 255 for each channel or the composite channel (where »rounding« would occur in that it combines three times 256 into 256 steps).

                      • 8. Re: check if all pixels are black
                        JimGoshorn Community Member

                        Adding a Threshold layer above the one you are checking and setting it to 1 should show anything that isn't black.

                         

                        Jim

                        • 9. Re: check if all pixels are black
                          Christian Davideck Community Member

                          c.pfaffenbichler wrote:

                          I wonder if You might be confusing the Histogram-display with the Histogram, 

                          There is a histogram palette which includes the histogram (graph). I am not sure what you are refering to by "Histogram-display".

                          (PS: in case you don't use the web-interface, I had made an edit to post #6)

                           

                          c.pfaffenbichler wrote:

                          which indicates the exact number of pixels of values 0 - 255 for each channel or the composite channel 

                           

                          I know, but I always ignored that approach (for the problem at hand), because I thought it would be too cumbersome to check all 254 values (from 1 to 255) to see if all have 0 occurence. But thinking of that, I just realized that I could simply set a threshold beforehand, so that I would only have to check a single value (255). thank you C.Pfaffenbichler! Sorry, I have only 5 points left to award, but your method does solve the problem equally well as Zeno's approach, so that's a second solution.

                           

                          c.pfaffenbichler wrote:

                          where »rounding« would occur in that it combines three times 256 into 256 steps

                          yes, I was only refering to the (visual) histogram graph. You can have values with "count>0" and they would still not display on the histogram graph.

                          • 10. Re: check if all pixels are black
                            Christian Davideck Community Member

                            JimGoshorn wrote:

                            Adding a Threshold layer above the one you are checking and setting it to 1 should show anything that isn't black. Jim

                             

                            >>>

                            Christian Davideck wrote:

                            I am working on very large images (a multiple of my screen's resolution) on a regular basis and [...] panning/zooming + eye-verification is error-prone and I would need an accurate and precise method.