Mobile app version of vmapp.org
Login or Join
Courtney577

: Remove white part of every color to make lighter parts more transparent My problem is so general, and there are version-dependent plug-ins for the problem not working with my version. I also

@Courtney577

Posted in: #AdobePhotoshop #BackgroundRemoval #Gimp

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.

10.04% popularity Vote Up Vote Down


Login to follow query

More posts by @Courtney577

4 Comments

Sorted by latest first Latest Oldest Best

 

@Vandalay110

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;
}

10% popularity Vote Up Vote Down


 

@Eichhorn212

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:


Download and install GIMP. (Scroll down for the Windows installer.)
Open your image in GIMP.
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).
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.

10% popularity Vote Up Vote Down


 

@Courtney577

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

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


open the image in cmyk mode, or change Image Mode to cmyk
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)
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
repeat 2 and 3 for Magenta, Yellow and Black
hide the original layer, delete the white background layer if exists, make sure that the new 4 piece of layer are visible
set the 4 layers visibility to darken or to multiply
set the Image Mode to rgb if you would like to

10% popularity Vote Up Vote Down


 

@Connie430

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme