Determine if layer is black and white (or desaturated)

Is there a way to programmatically determine if a layer of a PSD is black and white?

What mode are the images you want to check in anyway? CMYK, RGB …?
I suppose there are several options to achieve it.
• Iterating through the pixels with a ColorSampler would take too long for larger images, I guess.
• The Histogram would be unreliable because the numbers for each value in each Channel could accidentally be identical.
• But hiding other Layers, duplicating the image (mergeLayersOnly), changing to L*a*b, reading the a- and b-Histograms, closing the copy, un-hiding other Layers should work.
If the a- and b-Histograms are all bunched up around 127 (some tolerance could be set) it should be a desaturated Layer.
// check layer for 0 saturation;
// 2011, use it at your own risk;
#target photoshop;
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
hideShowOthers ();
// duplicate;
var theCopy = myDocument.duplicate("copy", true);
theCopy.changeMode(ChangeMode.LAB);
// get histograms;
var theA = theCopy.channels[1].histogram;
var theB = theCopy.channels[2].histogram;
// check histrograms;
var check = true;
check = checkHistogram (theA, check, 0);
check = checkHistogram (theB, check, 0);
// close;
theCopy.close(SaveOptions.DONOTSAVECHANGES);
// re-show;
hideShowOthers ();
if (check == true) {alert ("layer is desaturated")}
else{alert ("layer contains color")}
////// check histogram for cumulation around 227 //////
function checkHistogram (histogram, check, tolerance) {
     for (var m = 0; m < 126 - tolerance; m++) {
          if (histogram[m] != 0) {check =  false}
     for (var n = 255; m > 127 + tolerance; m--) {
          if (histogram[m] != 0) {check =  false}
     return check
////// hide/show all others //////
function hideShowOthers () {
// =======================================================
var idShw = charIDToTypeID( "Shw " );
    var desc2 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var list1 = new ActionList();
            var ref1 = new ActionReference();
            var idLyr = charIDToTypeID( "Lyr " );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idTrgt = charIDToTypeID( "Trgt" );
            ref1.putEnumerated( idLyr, idOrdn, idTrgt );
        list1.putReference( ref1 );
    desc2.putList( idnull, list1 );
    var idTglO = charIDToTypeID( "TglO" );
    desc2.putBoolean( idTglO, true );
executeAction( idShw, desc2, DialogModes.NO );
But someone else may have a better solution ready.

Similar Messages

  • Determining colors in a black and white photo

    I don't know if Photoshop can do this, but I really need to bring color to a black and white photo. I'm not looking to add color by imagining or guessing; I need to find out the actual colors. Is this possible? If photoshop can't do it but another program can, please let me know.
    Thank you.

    Just for interest sake, make a screen grab of your swatch panel, and paste it into a new Photoshop document.  Add a B&W adjustment layer, and have a think about what colour each shade of grey represents.  You can turn the B&W adjustment layer off and on again to help you along.

  • How do I save only an outline so I can layer ONLY black and white outlines?

    I am drawing cartoon outlines and then layer them in Photoshop Elements and color then in.  I want to save the file of each individual outline as ONLY the outline, not the outline and background.  Using the magnetic lasso to cut out the outline is very hard because it is complex.  I would rather just be able to save the outline with no background and I can then layer them.  Can anyone tell me if this is possible and what type of file do I use? TIFF? 

    Try making your drawing on a transparent layer. From Expert Mode choose:
    File >> New >> Blank File
    Set your document size (width & height) and choose a resolution of 72. Set background to white and click OK.
    Go to the menu and choose:
    Layer >> New >> Layer >> OK
    Now draw your cartoon on layer 1.
    When finished, highlight the background layer below layer 1 and click the trash can icon at the top of the layers pallet. Click OK to delete the layer.
    To save your drawing go to:
    File >> Save For Web
    From the dropdown list (near top right) choose PNG 24 which will preserve the transparency. Then click Save. Choose a file name & folder and click Save.
    You can now upload your drawing to any web page or send by email etc and the background page color will show through the transparency. Or it is ready to be colored in

  • How to determine actual colors in a black and white photo?

    I'm not sure if I'm in the right section, but I'm wondering if it's possible to use an Adobe program to restore actual colors in a black and white photo? I don't want add color by imagining or guessing; I need to determine the real colors. This might not even be possible, but if it is, please tell me what I can use.
    Thank you.

    That's where the artistry comes into play when they colorize old movies.
    A lady wears a nice dress:  is it greeen or purple?  It looks gray.
    A baby comes home from the hospital cute new baby clothes: pink or blue?  They look light gray.
    That's a nice school tie that guy's wearing: use the wrong colors on the stripes, and he's at a different school.  But they're nothing more than varying shades of gray.
    If there's one thing missing in a B&W photograph, it's any vestige of color information.   All you have is gray scale.   You may NEED to determine the real colors, but without a color photograph to use as a reference image, you're out of luck.

  • Swap black and White in layer mask

    How do I change the default settings for the layer mask, as I'd like to swap black and white color.

    hi steenmikkelsen2,
    white means that your mask is transparent until you fill it with black. since then, there was no option to change the mask default settings from white to black otherwise you have to do what Noel suggested. but i hope my suggestion will help you better.
    ►press "Alt" key on your keyboard simultaneously as you click on the "Add Layer Mask" button under the Layers panel. that switches a white layer mask to black. :-)

  • Apply Black and White to a layer?

    Hi,
         I would like to convert a layer in to Black and White. I have done it manually, I have select it in the following:
    Image Menu --> Adjustments --> Black & White.
         How do i apply the effect through scripting? Could you please guide me on this.
    thanks,
    Rajiv.S

    Record the ScriptingListener code for the creation of a B&W Adjustment Layer, then use that and combine it with something like
    app.activeDocument.activeLayer.merge()
    or
    app.activeDocument.activeLayer.grouped = true
    to merge or Clipping Mask it to the underlying Layer.

  • CS4: Black-and-White adjustment layer - no Saturation slider?

    Hi. The modal dialogue for Black and White has the "Colorize" option and for that "Hue" and "Saturation" sliders.
    But Black and White as an adjustment layer in the adjustments palette does NOT offer the Saturation slider. At least not in my CS4 Extended on Win XP. There is the targeted adjustment tool (TAT), but it changes color, not saturation.
    Can that be or am i missing something?
    Thanks!

    The interesting thing is that there is an colorization saturation adjustment slider in the imag-adjustment-black and white dialog as shown below.
    The lack of that slider in the adjustment panel is a bug in CS4. It was present in CS3.
    Adobe should fix that because it is really usefull because it's non-destructive and can be set as a preference.
    The cumbersome workaround is to add a hue saturation adjustment layer.

  • I hired a commercial artist to create a color image for the cover of a self published book. I want a black and white image for the inside. The commercial artist has not responded to this request. How do I determine the format of the color image, I'm guess

    I hired a commercial artist to create a color image for the cover of a self published book. I want a black and white image for the inside. The commercial artist has not responded to this request. How do I determine the format of the color image, I'm guessing it's Illustrator's formatting but I don't know. How can I find out if Illustrator will open the file and allow alterations? The image opens only in Apple's Pages software?

    rons,
    It seems that all you have is a raster image, presumable PNG24 or JPEG, in RGB.
    It may have been created as raster artwork in Photoshop, or it may have been created as vector artwork with the help of Illy, or as a mixture of vector and raster artwork in either application, or both combined.
    If you just need to have a raster representation in black and white based on the current colour image, you may try this, in a new RGB document (View>Smart Guides are your friends):
    1) File>Place the image (you may tick Link or untick and have it embedded);
    2) Create a rectangle with black fill (R = G = B = 0), at least as large as the image, and place it behind the image (you may ClickDrag with the Rectangle Tool between opposite corners, then Ctrl/Cmd+X+B);
    3) Select all and in the Transparnecy palette flyout click Make Opacity Mask with both Clip and Invert Mask ticked.

  • How to copy a black and white layer to the mask of another layer.....

    Earlier I asked, "How?"
    Got a reply, but the solution didn't work in PSE 10. 
    After trial and error, I figured it out.
    When dealing with abstract art or even hair, it is too time consuming to make a
    mask pixel by pixel.
    Load the image you want to mask into a new layer and convert it to black and white.  You might need to
    adjust contrast/brightness to maximize the effect..
    Using the Magic Wand tool, click on the WHITE area of the image.   
    Click Edit/Copy.
    Click on the layer you want the mask copied to.
    Next, click on "Add new layer mask" button on the bottom of the layers panel. 
    Your mask should appear and is now ready for a touching up!.

    What’s the correct way to proceed?
    Joke?
    In Photoshop there are often more ways than one to achieve a task and none of them need be considered »wrong« as long as the result fits the intention, so »the correct way« seems to be problematic terminology.
    Anyway, one can use a Layer set to Blend Mode Color and paint on that with whatever colors.
    Or one can use Solid Color Layers set to Blend Mode Color.
    Or Hue/Saturation Layers …
    To edit contrast if necessary Curves or Levels Adjustment Layers can be employed.
    You could also have googled »photoshop colorize black and white« …

  • Q: How do I Mask/Layer a color photo with a black and white photo?

    This is what I want to do. I've done it before but cannot remember for the life of me how to do it again. I want to put a color photo under (its own) black and white photo and then erase or remove or something (I can't remember the tool to do it) but I want to be able to see some of the color photo in my black and white photo. For example, say I have a pic of the Disneyland Castle. I want to make the pic black and white and then with a layer or mask (whichever one) have the exact colors of the picture underneith it show up after I have used the paint brush to remove the black and white...is anyone understanding me? When I did it before I know I did it in only a few steps, it wasn't super complicated, and I'm probably stupid for not knowing how to do it now. Thanks!
    Lindsey Henry

    Lindsey,
    First, look at the Channels in the B/W. Probably, you can use one of those as a Selection and then as a Layer Mask. If not perfect, then you can likely get close. If you need to, you might want to Blend more than one of those Channels.
    If you have an issue "collecting" the Channels, just get your B/W into a separate Image, and then drag individual Channels back to your composite image, and use them, as is necessary.
    Hope that some of those ideas are useful,
    Hunt
    BTW - turn OFF the color for Channels, so that you can see them as B/W, as that will help you see their makeup.

  • Extracting Photograph Noise as a black and white layer from Photograph

    I am looking to extract natural noise from a photographs material and create a black and white layer out of it, but I am new to photoshop and unsure how to proceed with this.
    For example, here is a photograph of a hard plastic gun.
    [IMG]http://dl.dropbox.com/u/2871613/racer/G36.jpg[/IMG]
    I have seen on forums where users will find a good reference image and use it to create a new black and white noise picture utilizing the reference.
    For instance the hard plastic noise from the gun, might look like this once extracted and done correctly.
    [IMG]http://img.photobucket.com/albums/v11/wwarriorww/hard_plastic.png[/IMG]
    Any ideas on how to produce something such as this?
    Thank you

    This is just off the top of my head...  You could try something like this:
    1.  Duplicate the image as a second layer.
    2.  Run a noise-reduction tool with aggressive settings, possibly multiple times.
    3.  Set the noise-reduced layer to Difference.
    4.  Merge layers.
    5.  Filter - Other - High Pass.
    6.  Enhance the magnitude of the result with a curves or levels operation.
    -Noel

  • Colored texture pasting as black and white into a layer mask

    Hello all,
    First time poster, long time lurker here.
    I'm pasting a colored layer into a layer mask I created  in order to texturize a shape I made. Whenever I Option + Click the layer mask and then paste the texture, it pastes in black and white instead of color, see screen capture below (pardon the watermark):
    http://www.youtube.com/watch?v=wC8Da4V0FAc
    Am I missing something here? Thanks in advance!

    If you want to add a texture to a shape, create a new layer, fill it with your texture, then ALT+click their separation line in the layers panel.
    This creates a what is called a Clipping Mask: http://helpx.adobe.com/photoshop/using/revealing-layers-clipping-masks.html.

  • Cc opacity keyframe on black and white adjustment layer doesn't work

    hi
    i use premiere cc under w8.1 pro
    well i noticed a strange behavior
    i added an adjustament layer , black and white effect , and several keyframes
    seems that premiere reads only the first one
    for example
    1) keyframe -> @0%  the second keyframe @100%  the video is all in color ,doesn't matter how many keyframes i add
    2) first key @100% second @0% (opacity) the video is all in black and white , again doesn't matter how many keyframes i add , only the first is read
    i tried the black and white effect , on video ,titles and so on and it works perfectly , it doesn't work on the adjustament layer
    i tried others effects on adjustament layer and they work
    is a bug ?
    is there an known bug in prev. versions?
    thanks

    thanks i do it, saturation
    but can't understand why this happen with adjustament layer only
    may i know which cc version do you use?
    sometime i think to buy c6 , i have cc subscription

  • Original picture turns black and white when adding layer masks.

    Creating a collage. Just placed a new object with a layer mask. Now I need to create a hue/saturation, levels adjustment layer and color balance adjustment layer all with masks. Ok, no problem, but when I do this, my original picture turns black and white. HELP!!! School project and has to be completed by Monday morning.
    Thanks. Dawn

    You haven't added a Hue/Saturation layer that's got Saturation turned all the way down, by chance?
    It might be helpful if you'd capture a screen grab and post it here, showing your layers and channels panels.  With a look at how things are organized knowledgeable folks here should be able to help or at least ask more direct questions.
    -Noel

  • Black and white a adjustment layer not working

    Hi every one. I know this is going to sound really dumb but I am looking to change a color logo to bw. I wanted to use the black and white adjustment layer but the option is greyed out. Is there a step I am missing? The file is cmyk and is 8bit. I am using PS  CS6. What do I need to do to make this option available?

    The only dumb question, is the one you do not ask.

Maybe you are looking for

  • Use-exit to update

    Hi I seek another to use-exit to update the zone kna1-bahns. gv_n = 0.   IF i_kna1-bahns IS NOT INITIAL .   ELSE.     gv_bahns = i_kna1-name1+0(4).    DO gv_n TIMES.       gv_n = gv_n + 1.       SELECT SINGLE kunnr FROM kna1 INTO kna1-kunnr         W

  • File size in SWF header

    Hi All, Is there some way to avoid adding the uncompressed file length to the SWF header? (the 4 byte integer after the 3 byte signature and the 1 byte version number) Can I write some default value instead of the exact one? Any help would be highly

  • IMessage is not avaiable on my iPad

    There is no icon and a search on the iPad finds nothing. How do I go about getting it on my iPad?

  • Desktop error when importing tracks from a CD

    Hi all, using the latest version of iTunes (6.0.1.3), whenever I try to import tracks from a CD into my library, I get a popup from the OS that says: "Desktop: Access to the specified device, path, or file is denied." The tracks import just fine, so

  • Import data definition from ttx file

    Post Author: chamalsl CA Forum: Data Connectivity and SQL Hi, I have a report where data fields are imported from a ttx file. But the ttx file is missing. 1. Is there a way to add a new data field to this report without the ttx file. 2. Or is there a