Take the 2-minute tour ×
Graphic Design Stack Exchange is a question and answer site for Graphic Design professionals, students, and enthusiasts. It's 100% free, no registration required.

My problem is so general, and there are version-dependent plug-ins for the problem not working with my version. I also found workarounds that are not the correct solutions.

I would to convert my image's white to transparency, i.e. decompose gray to black and transparent. It would be correct if I could use the saturation value of the pixel from the HSB (de)composition, make every pixel's saturation to 100% from it's original s(x,y) value, and add a 100% - s(x,y) transparency to the pixel.

As the mentioned and many other workaround suggest, using the image itself as an alpha channel is not a solution. E.g. if the pixel is 20% white and 80% gray, and you apply a 20% transparency, then the pixel will look look like 80% - 0.8*0.2 = 56% black instead of 80%.

Another stackexchange question on turning white to transparent is similar to my problem but as I understand, it does not cover my problem. In case if I'm wrong I'd appriciate if someone enlight me how to apply that for my scenario.

share|improve this question
    
So do you want grey to be transparent at all? –  John Jul 28 '13 at 21:53
    
I want gray to become black and half transparent. If it is e.g. 30% black 70% white, it should be 100% black and 70% transparent. –  DanielTuzes Jul 31 '13 at 11:50
    
If the pixel is 20% white and 80% grey (which is 80% black and 20% grey), you would apply 40% (20% white + 20% white) transparency and get around 60% transparent black, a grey, which is what I would expect. No? –  Stan Sep 1 '13 at 1:43
    
If I understand what you wish to do, Faber Birren's "Colour Equations" will indicate what proportions are necessary for the black, white, and the hue for any image. By substituting X-parency for the white, % values of black, and the hue can be determined. –  Stan Sep 1 '13 at 2:31

4 Answers 4

up vote 1 down vote accepted

I know you asked how to do this in Photoshop, but this may be one of the few cases (now that Photoshop has content-aware fill too) where GIMP does the job better. So my suggested solution would be:

  1. Download and install GIMP. (Scroll down for the Windows installer.)

  2. Open your image in GIMP.

  3. Use the Color to Alpha tool to convert white to transparent (masking and tweaking as needed, if you want to retain some non-transparent white in the result).

  4. Save the resulting image and reopen it in Photoshop.

Note: GIMP can import and export Photoshop .psd files, but some information may be lost during the back-and-forth conversion. It may be safer to only edit your PSD files in Photoshop, and to use the PNG format for transferring images between Photoshop and GIMP instead.

share|improve this answer
    
This is exactly what I was looking for. A used the tag adobe-photoshop but I didn't state that you must provide a solution with that program only :) –  DanielTuzes Sep 4 '13 at 15:52

You can't change gray to black and make the white transparent in one method. The only way to do it without masking, is if you are happy to change the levels on your entire image. So if you have something colored for example in the image you would have to mask that.

(Duplicate your image layer first and hide it for backup) On your layer create a layer mask. select all of your image and ctrl+shift+c copy it. Alt+click on your layer mask icon in the layers panel to activate it. ctrl+shift+v paste it into there. Deselect and ctrl+i to invert the colors. All the white areas should be black now, meaning they are 100% masked out.

Now create a threshold adjustment layer. this should make the layer below (your image layer) turn pure black and white. Adjust the balance as needed and add a layer mask to the threshold if you have colored areas that you don't want converted from gray to black. Select all ctrl+shift+c copy and paste onto your original image layer.

The result should be a black and white version of your image with it's original black and white (non threshold) values driving the transparency layer. Your 20% grays will now appear as 20% blacks.

share|improve this answer
    
1: I'm not looking for a one step method. 2: My aims are pretty simple and I can present my wishes with formulas and equations too. Photoshop is an advanced program, I bet there's way to do what I want. 3: The solution you provided is just similar to other's what I try to avoid. 4: I forgot to emphasize, but the description implicitly contains: any "as needed" solution is not acceptable. 5: Thank you for your answer anyway :) –  DanielTuzes Aug 1 '13 at 21:26
    
@DanielTuzes I'm not sure how formulas are an effective way to describe what you are after. From my understanding you wanted black where your grays are, but the transparency to be the grays black-white value driven. I've described the easiest way to do this without creating a custom script/action. Not sure how it can be interpreted as an as needed solution, simply because I added a if-this-you-need-to-do-this note. I'm really not sure what else you are asking for... –  John Aug 1 '13 at 21:43

Just out of curiosity, I came up with a proof-of-concept script for PS to do what you suggested, but unfortunately it is extremely slow. If you want to test it, make a new document around 25px square, name the base layer "base" and then add two empty layers named "Alpha" and "HSB". The alpha layer gets filled with pixels that have a grey value (in RGB) based upon the S value, and the HSB layer gets filled with pixels which have the S value modified to 100. The Alpha layer can be used as a layer mask for the HSB layer (select all, add layer mask to HSB layer, switch to channels and paste the copied alpha layer into the HSB mask channel).

If you hide all palettes, it appears to run slightly faster, but a real image is "go get coffee and maybe do a little shopping" slow. "Take a nap" slow.

var currDoc = app.activeDocument;

var sampler = currDoc.colorSamplers.add([0,0]);
for (var x = 0; x < currDoc.width; ++x) {
    for (var y = 0; y < currDoc.height; ++y) {
        currDoc.activeLayer = currDoc.artLayers.getByName("base");
        sampler.move([x,y]);

        var result = selectPixel(x,y, currDoc);
        result = setPixelColorHSB(sampler.color, currDoc);
        result = setPixelColorALPHA(sampler.color, currDoc);

    }
}
sampler = null;
currDoc.selection.deselect;

function setPixelColorHSB(pixelColor, currDoc)  {
    currDoc.activeLayer = currDoc.artLayers.getByName("HSB");
    currDoc.activeLayer.visible = true;

    var color = new SolidColor();

    color.hsb.hue = pixelColor.hsb.hue;
    color.hsb.saturation = 100;
    color.hsb.brightness=pixelColor.hsb.brightness;

    currDoc.selection.fill(color);
    currDoc.activeLayer.visible = false;
    return true;
}

function setPixelColorALPHA(pixelColor, currDoc)    {
    currDoc.activeLayer = currDoc.artLayers.getByName("ALPHA");
    currDoc.activeLayer.visible = true;

    var color = new SolidColor();

    color.rgb.red = Math.floor((pixelColor.hsb.saturation/100) * 255);
    color.rgb.green = color.rgb.red;
    color.rgb.blue = color.rgb.red;

    currDoc.selection.fill(color);
    currDoc.activeLayer.visible = false;
    return true;
}

function selectPixel (pixX, pixY, currDoc)  {
    currDoc.selection.deselect;
    var selRegion = null;
    selRegion = [
        [pixX, pixY],
        [pixX + 1, pixY],
        [pixX + 1, pixY + 1],
        [pixX, pixY + 1],
        [pixX, pixY]
        ];
    currDoc.selection.select(selRegion);
    return true;
}
share|improve this answer
    
+1 for the effort of writing a script, no matter how many naps you need to take while waiting for it to finish. –  Johannes Sep 4 '13 at 18:44

I found out a way that fits to my requirements. I share it with you so you may criticise it. I'm looking for further improvements so feel free to add your notes or answers!

Unfortunatelly this solution is not general because of the usage of the cmyk channel. But with this procedure you can get this enter image description here

from this one: enter image description here (download tha pictures and view transparency if you don't see differences)

  1. open the image in cmyk mode, or change Image Mode to cmyk
  2. create a new alpha channel Alpha Cyan based on the Cyan channel: on the channels panel, make visible and select Cyan, copy it (select all, ctrl+c); create a new layer Alpha Cyan and insert the Cyan channel already copied to the clipboard (ctrl+v)
  3. make visible the cmyk channels only and insert a new layer with cyan solid color, so on the layers panel, create a new layer; add a cyan solid color to it, name it to Color Fill Cyan; add a vector mask to it; load the Alpha Cyan channel and save to channel Color Fill Cyan Mask
  4. repeat 2 and 3 for Magenta, Yellow and Black
  5. hide the original layer, delete the white background layer if exists, make sure that the new 4 piece of layer are visible
  6. set the 4 layers visibility to darken or to multiply
  7. set the Image Mode to rgb if you would like to
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.