Welcome to the forum!

As an adjunct to the Tangents blog, the intention with this forum is to answer any questions, and allow a diverse discussion of topics related photography. With that, see it as an open invitation to just climb in and start threads and to respond to any threads.

Photoshop tips: Masking - getting background white behind hair

SkipperlangeSkipperlange Member
edited February 2015 in post-processing

Hi: Does anyone know if there is a way to remove all of a certain color in a photo? For example, "Please remove all of color 123456." I shot some portraits which need to be against a white background. I lit my white background paper with a light to ensure that it would be bright white. However, it's not totally white. I was a bit conservative on the light in order not to put backlighting on my subjects. I have a small space and it was not possible to separate the subjects from the background as much as I would have liked. There was a strong risk of my light reflecting back on them. 

So for most subjects I can either use the extract tool, which works well, or, for some, I can select the background and fill with 100 percent white. However, hair is the problem. If it's not too wild, extract works well. But for one woman, I've tried over and over with extract as well as trying to brush out the gray with low opacity eraser and other tricks, none of which are working. Every result is horrible and looks fake and Photoshopped. So I am wondering if there's a tool or method to remove this gray color from within the hair while leaving the hair intact and natural. Here is a photo attached. 

Thank you!


Comments

  • I doubt you'll be able to do it by applying a background fill then erasing.  The best way and most accurate way to extract hair is through Channel Masking....If you post a larger image I'll try to walk you through the process.
  • Thank you Jan1215. I can't post a larger image since I don't have this woman's permission to post her photo. But I will look up channel masking. I've never had much luck with masking -- I can't seem to grasp even what it is never mind doing it. But I'll take another stab at it as I'd love to be able to do this properly. Thank you I'll let you know how I make out. 
  • You can do a quick selection and then refine selection followed by inverse selection


    5 minutes well spent
  • Thanks Rudy. I have been trying the selection tools and refining the edges but nothing I'm doing is separating the hair from the background so I'm ending up with blocks of gray background around and throughout the hair. I have another subject I'm working on also who is actually even more difficult. It's funny because on less fuzzy hair, even on women's layered hair, the extract tool works like a charm. But for this it doesn't seem to. I'm going to take Jan1215 up on his/her offer and post a photo which I can still edit (delete) within a week since I will not have permission to post it. 
  • SkipperlangeSkipperlange Member
    edited February 2015
    Jan1215: Thank you, I will take you up on your kind offer -- if you are still willing -- to walk me thru channel masking so that this man's fuzzy hair (new photo) can be separated from the image and the background can be bright white. I looked up some channel masking tutorials and they all assumed I already knew more than I do. I have one week to edit this post so I will be able to remove the photo in time, as I do not have permission to post it. Thanks again. 

    The hair on top of his head is the problem, not on the side.
  • jan1215jan1215 Member
    edited February 2015
    There are literally countless ways to make masks and selections in Photoshop; it all depends on the subject and the contrast with the background.  This image is not particularly difficult to extract the subject even with thinning hair.

    I tried two quick approaches to extracting the subject and replacing the background with near pure white (238, 238, 238).  Tell me which approach you prefer and I'll walk you through the steps.  Note that this is applicable to only this image; another image will present different challenges so its useful to know how to use all the selection tools in Photoshop.

     First, I used the Quick Select tool in combination with the Refine Edge Tool to extract the subject, then created a new layer and filled it with the requested color.
    image


    Second, I created a mask using the Calculations command in Photoshop, then used the mask to obscure the old background and allow the new background to be revealed.  Here's the result and the mask I used:

    image


    image




  • Phlearn just published a concise tutorial on using the Refine Edge tool to quickly and accurately mask out hair.  Perfect for this application.

  • Hi Skip

    I've had a similar issue when shooting against a white background. To fix it I used the blending modes in PS with good results.
    Basically I created a new layer above the image, then painted the background area with 100% white and painted into the subjects hair by an amount.
    Then use the layer blending options (double click the layer), so that you do not show white (current layer)  where the underlying layer is darker.
    If I remember correctly this would mean moving the left slider towards the right, you can fine tune it by hold the 'alt'key and splitting the slider.

    Obviously if the hair is white then this will not work.
  • Thanks Jan. They look great. I think I'd like to take a stab at the second approach, creating a mask. I actually think I may've tried your first approach after finding a tutorial that sounds like what you did. It did not go so well. So maybe I'll have better luck with your option 2. Thank you! 
  • SkipperlangeSkipperlange Member
    edited February 2015
    Thank you DaBears. I'll take a look at that. I was trying to trying to use the Refine Edge Tool today and got lost. (Not the quick refine edge button but the window with a variety of options). Wow, just saw that you can play that tutorial right here on the forum without opening a new window. That's handy!
  • Thanks TonyT. It's good to know there's a way out of this, between your post and the others. I think I should just try to get the background white in the first place although that's tricky too for reasons I stated in my first post -- blowback onto subject. Thanks for this guide. This is all well above what I am used to doing so it will take me a while to figure out what you were saying. I don't use any of those tools but wow, wish I did as it would speed things up. 
  • Neil vNNeil vN Administrator
    Jan ... thank you! 
  • Its probably going to take me longer to write out these steps than to actually swap the backgrounds.

    The first rule you need to understand when masking is that White Reveals, Black Conceals.  So since you're interested in removing the subject from the existing background the final result of your mask should be the subject is entirely white and the rest of the image is black.  How you eventually get there is up to you; given the number of selection tools in Photoshop there are countless method to achieve a perfect mask, although some selection tools work better than others.

    Anyway, I went "old school" with the second version.
    First I opened the photo in Photoshop, went to the Channels palette, and compared the contrast between the hair and the background for each of the individual channels.  I decided that the Blue channel showed the most contrast between hair and background.  Now with the Blue channel still selected I clicked on Image > Calculations in the menu bar and set the dialog box that appeared to the following options;

    Source 1:
    Layer - Background
    Channel - Red

    Source 2:
    Layer - Background
    Channel - Blue

    Blending - Add
    Opacity 100%, Offset -255, Scale 1

    Result: New Channel

    The reasons for these settings require a knowledge of blend mode mathematics which is beyond a simple tutorial.  Suffice it to say these settings work with this particular image.

    Once you press the "OK" button, you will see a new channel appear called an alpha channel...that's simply a fancy name for a saved selection. Click on this new channel to select it, then use a large soft black brush to paint in the portions of the subject that are not black.  When you get to the edges of clothing or near his hair switch the brush blend mode to Overlay and continue painting black. Don't paint over the fine hairs at the top and side of his head, we can fix that later.


    Now use your Lasso tool to draw a rough outline around your subject, taking care NOT to include any hair or clothing.  Invert your selection by pressing CTRL+SHIFT+I, and Fill with white.  The final step is to press CTRL + I to invert the alpha channel so that the subject appears white and the background is black.  If the alpha channel is not entirely black and white, use the Image > Adjustments > Levels command and move the black and white markers until they are positioned at the start of the peaks.

    If you followed the prior instructions you should now have a perfect mask in the alpha channel.  Now press CTRL and click on the alpha channel thumbnail to load it as a selection. Select the RGB composite channel at the top of the stack, then switch to the Layers palette.

    In the Layers palette, duplicate the background layer, select the duplicated layer and click on the "Add Layer Mask" icon. (its the third icon from the left at the bottom of the Layers palette). Click on the original background layer, then add a new layer and fill with white.  You should now have 3 layers in the following order from the bottom; the original background layer, the white fill layer, and the duplicated background layer with the layer mask. The mask on the top layer "knocks out" the original background so that the new background on the middle layer replaces it.

    The final step is to refine the mask to eliminate color fringing/bleed through around the fine hairs.  Click on the mask thumbnail to select it, grab a soft white brush set to Normal mode and 20 percent opacity and gently paint away any areas where the mask is imprecise like his forehead and hairs.  If you want to reverse, set the brush to black (remember the rule "White reveals, black conceals."

  • Thanks Jan! Printing it out now. I'll let you know how it goes. Thank you very much.
  • In paragraph 5 you wrote "Click on this new channel to select it, then use a large soft black brush to paint in the portions of the subject that are not black." My problem is (see screen shot) where do I paint with this black brush because I have an entirely white photo? Also, which tool is the brush? Is it the 'brush tool' that stamps 'brush' stamps such as logos? Do I just paint the whole thing black? I can't see the subject, as you can see. Do I get the brush black the same way I change colors when writing with the pencil tool, using those little squares at the bottom of the tool bar? Thanks!
  • I might or might not have figured out why my photo as all white after creating the alpha channel. I went back to calculations and below the blending section there was an unchecked box called 'mask' so I checked it and got some other options and replaced the word gray with the word blue and hit OK. Now I have a black and white photo if the new alpha channel is selected. Is this right? See photo here. 

    Not sure if that was the problem but I continued on and ran into all kinds of problems. So this will take a while. Will keep trying. Thanks again very much. 
  • In the Calculations dialog box, the Offset setting is -255... that is minus 255.  Your screenshot shows you're using 255 so you're getting a different result. 

    Press the B key to invoke the Brush tool.  To reset the colors press the D key and they will be set to Black and White.  To switch between the colors press the X key.
  • I am at the point where the tutorial says 'Now use your lasso tool to draw a rough line around your subject…….. The final step is to press CTRL + i to invert the alpha channel so that the subject appears white and the background is black.' Here's where I may've done something wrong. 

    In image Mask3 I've got my black brushed-in subject outlined and ready to fill in the selection with white via Edit - Fill. In Mask4 I have a three-colored image, not entirely black and white as the directions say. So I go to levels. Sliding the right and left knobs dramatically will produce a variety of black and white images, some with and without the fuzzy hair included, so not sure which is the right way. Not sure where the 'peaks' mentioned in the tutorial are. (Should I get rid of the dancing ants?)

    Settling on one version, if I then press CTRL and click on the alpha channel but nothing happens. 

    Thanks again.
  • jan1215jan1215 Member
    edited February 2015
    I apologize if the tutorial is unclear but I'm sure you appreciate how difficult it is to provide detailed explanations of each step.

    When you make the rough selection of the subject using Lasso Tool, you can go a bit tighter than the selection shown in your screen capture; just make sure you don't encroach on any of the clothing or especially any of the hair.  Once the rough selection is made, press the CTRL/CMD + SHIFT + I keystroke combination (That's the reverse selection command) so that now most of the background is selected instead of the subject.  With the selection still active fill with White, the press CTRL + D to deselect the selection.

    Once you've deselected, press CTRL + I (the Invert command, which is different from the Inverse Selection command done one step earlier).  The Invert command makes the subject white and the background black.

    The peaks in the Levels dialog box refers to the spikes in the  histogram, setting the Input Levels as white to 180 and black to 15 should remove most of the grey fringing around your subject without affecting his hair.  This technique is called "Choking the Mask."  You want to adjust the Levels to the extent that the grey fringe around the clothing is removed by the hair is unaltered; this is important because he has salt and pepper hair and if you're too aggressive you will end up removing the fine hairs which are neither really white or black from the mask.  You can see how I did it by looking at the image of the mask I posted earlier.

    Once you've made the Levels adjustment, there migh still be a small amount of grey fringing.  You can remove that by selecting a White Brush set to 100% Opacity and  Overlay Mode and paint away the grey fringe around the clothing.  Avoid painting over any hair.  The best way to paint is to make sure your white brush barely touches the black portions of the subject's clothing.  Again, avoid painting over any hairs, that is addressed in another step.
  • To load the mask as a selection, click on the Alpha channel THUMBNAIL while holding down the CTRL/CMD key.  I suspect you're clicking on the channel name and not the thumbnail.
  • Oh my goodness, don't apologize! Your tutorial is fabulous and I am really appreciative that you took the time to write it and then to follow up and in such detail. It's not you, it's me. :-) You need to really dumb it down for me. Thank you for your latest chapters. Yes, I was clicking on alpha channel name. I will keep plugging away at it. As this photo was needed the one you did was actually large enough to use so I sent it to them. They wanted bright white but I think your slightly off white may do. He sent me a note back saying he loved it. So I owe you something. 

    I will work on this though so that I have a larger copy and bright white ready as the business may say they want bright white. Or not, maybe it's not possible given how light and thin the hair is. Also, I run into this a lot so really need to learn it. I'll let you know how it goes. Thanks again.
  • Hit a roadblock here: "If you followed the prior instructions you should now have a perfect mask in the alpha channel.  Now press CTRL and click on the alpha channel thumbnail to load it as a selection. Select the RGB composite channel at the top of the stack, then switch to the Layers palette."

    If I hold down the ctrl button and click on the alpha channel thumbnail I get a drop down menu with two options: duplicate channel and delete channel.

    If I hold down the Apple/cloverleaf button and click on the alpha channel thumbnail I get marching ants in two rows around the white halo of my subject, one row on border with man; one row on border with black background. 

    Nothing I get suggests I am loading the alpha channel as a selection. What am I doing wrong? Thanks!
  • jan1215jan1215 Member
    edited February 2015
    In both screen captures the alpha channel is loaded.  Since you're on a Mac, CMD + clicking on the alpha channel thumbnail will load the channel as a selection.  Alternatively you can drag the channel down to the first icon from the left at the bottom of the Channel palette that looks like a circle of dots - that's the load channel as selection icon.

    But like I said the alpha channel is loaded, you can see the "marching ants" indicating a selection in both screen caps.  But how you got to the point where both the background and the subject are black isn't clear to me.  If you followed all the steps, your subject should be white (and shades of grey around the flyaway hairs) and the background is black.  So when you load the alpha channel only the white areas are loaded and are indicated by the "marching ants."

    EDIT: It looks like at some point you inverted the selection when you should have deselected the original selection by pressing CTRL + D as outlined in my preceding comment.
  • Ok thank you. I will try again. I think I am confused by the invert and inverse. And I don't know what it's supposed to look like so that doesn't help. 

    Is the CMD button the Apple/cloverleaf button? Thanks.
  • Just follow along the directions slowly; its all outlined there.  I suppose much of your struggle is that you aren't that acquainted with Photoshop.

    Yes, the cloverleaf key is the same as the Command/CMD key.
  • SkipperlangeSkipperlange Member
    edited February 2015
    Part of the problem is not knowing which are the command and control keys. This is the step(s) I am stuck on now: 

    "Now use your Lasso tool to draw a rough outline around your subject, taking care NOT to include any hair or clothing.  Invert your selection by pressing CTRL+SHIFT+I, and Fill with white.  The final step is to press CTRL + I to invert the alpha channel so that the subject appears white and the background is black.  If the alpha channel is not entirely black and white, use the Image > Adjustments > Levels command and move the black and white markers until they are positioned at the start of the peaks."

    When I hit CTRL + I all that does is hide the channels palette. The photo does not change. Also, in the step immediately before that, when I inverted the selection the selection automatically got white. I did not need to fill it white. So I said OK, fine, it's white. Then I hit CTRL + I and all that did was hide the channels palette (and the background is two tones of gray, the darker tone filling in between the man and my rough cut selection border.)



  • This is what I have after roughly outlining my subject after painting him black. This is after completing the step copied below. 

    "Now use your Lasso tool to draw a rough outline around your subject, taking care NOT to include any hair or clothing." 
  • If I then hit CTRL+SHIFT+I all that happens is the channels palette disappears. If I press it again the channels palette reappears and so on. 

    If I go to Image -- Adjustments -- Invert then the man turns white and the background becomes two tones of gray. (see photo)
  • Jan, I really appreciate your help. Please don't feel you are stuck with me now and have to hang in there. This has been great, I can watch some tutorials and maybe piece it all together. I have a few missing pieces here (because of my lack of grasping it, not because your tutorial is not clear) but I'll try to get it right. So feel free to be done with this. Or, if you want to keep going that's fine too. 

    Thanks very much.
  • Here's a link to a file with the Photoshop keyboard shortcuts for Mac and PC, you can use it as a handy reference:  http://phlearn.com/photoshop-keyboard-shortcuts

    Youre still confusing some steps; so let's go over them again.
    1.  Once you get to the stage of your alpha channel where the subject is black and the background is greyish white, do the rough selection of the subject, inverse the rough selection by pressing SHIFT + CMD + I (the 9th letter of the alphabet), then Fill with white.
    2.  After filling with White, press the CMD + D keyboard shortcut to deselect (THIS IS ONE STEP I THINK YOU'RE MISSING).  The selection is still active after filling with White so if you don't deselect you will get unpredictable results.
    3.  After deselecting, press CMD + I to invert the entire channel.  Your subject will now be white and your background is black.\

    The last snapshot is exactly what it should look like before filling the background with white.  Keep and it and it will become clear to  you.  The problem youre encountering in Mask (B) is because you didn't deselect the entire image before inverting.
    I know the words "Inverse" and "Invert" are confusing....Inverse relates only to when you're making selections and it means that you're telling Photoshop to grab the opposite of what you initially selected.  Invert relates to the entire layer and it means you're reversing the luminance levels so that all white pixels become black and all black pixels become white.
  • SkipperlangeSkipperlange Member
    edited February 2015
    Success! Thank you Jan. 
  • I'm glad you got it sorted out.  Regarding the subject's hair, my guess is that you were too aggressive with either your Levels adjustment, or in painting in the details with the Black brush in Overlay mode.  If you look at the copy of the mask I posted you will see that I painted in up to the hard edges in the subjects clothing but I left the area around his hair untouched.

    With fine details like hair, its best to leave whatever was automatically selected by Photoshop alone when crafting the alpha channel.  You can always adjust it later by modifying Layer Opacity when the alpha channel is applied as a mask.
  • groomsphotogroomsphoto Member
    edited February 2015
  • Thanks Groomsphoto. That looks good!
Sign In or Register to comment.