View Full Version : Getting rid of background


Claude
07-25-2003, 03:24 AM
Hello,
It is a common problem in microphotography that the illumination of the microscope field is not completely uniform.
Question: would it be thinkable to take two photos, #1 of the empty field, #2 with the object and combine them in one psd as layers and substract #1 from #2 to get rid of the background?
Masking is out of the question due to the contorted character of the object and the unavoidable loss of edge detail in touching up the mask.
I hope I did not miss the obvious answer to this in Richard's book,wich I confess to be still digesting.

pmarchant
07-25-2003, 05:39 PM
... it's just how you create the mask.

Try this:
1. Start with two layers:
-- the bottom layer is your picture #2, label this 'image'
-- top layer is picture #1, label this 'bg'
2. duplicate the image layer and move it to the top, so that the layer stack is:
image copy
bg
image
3. with the 'image copy' layer selected, change the blend mode to "difference" and merge down (command/ctrl+E)
4. use the HP tools "Clear Black" and "Commit Transparency" and rename the resulting layer 'mask'

You'll find that the bg layer has now been replaced by the mask layer. To use the mask layer:
1. duplicate the image layer and move to the top.
2. group the 'image copy' layer with the mask layer (command/ctrl+G)
3. select the image layer and create a new fill layer

You'll find the background replaced by the fill layer's content.

Note this'll only work if the background you want to remove is the same in both pictures (so that the 'difference' in the RGB values is '0' and thus renders as black)

Cheers,
Paul.

Richard_Lynch
07-25-2003, 07:59 PM
Hmmm. Somebody's been studying their Hidden tools. Difference mode is indeed a good solution IF the lighting will be identical between shots and IF the object being introduced is not completely opaque in areas.

Nice solution Paul.

Claude
07-26-2003, 09:02 AM
Paul,

Thank you for a quick and very clear answer!:) :)
It works beautifully. one little point though: "Clear black" did'nt work but "Drop Black" did; Ctrl+E did'nt work but Ctrl+G did.
Any comments ?

Richard,

Thanks for dropping in. Both ifs are met
What part of your book should I have read more attentively?

Richard_Lynch
07-26-2003, 09:15 AM
What part of your book should I have read more attentively? Well, I don't know that Paul's solution was something you'd get directly from readig the book unless you REALLY DIGESTED the whole thing. That is a combo of CMYK separation and layer masking...very much something he could have come up with based on those techniques, but I don't know that it isn't something else.

As far as the difference between drop and clear black...it sometimes depends on what you are doing, and I think either of these will work. You want to group with the mask and commit the transparency (so it is actually transparent rather than just invisible). If you aren't sure why you are doing either of these, I'd re-read those sections too.

I don't know that I said anything there...did it help?

Claude
07-26-2003, 10:54 AM
[QUOTE]...really digested..
I suspect that is still going to take some time:)
I recently got my hands on a copy of Photoshop 6, so the temptation lurks to make the whole thing an action .

BUT the process uses your HPE1 tools...so the question becomes: can I just copy (or install..) them in the action directory of Photoshop 6 ?

OR do I have to fish out the equivalent steps in Photoshop 6 ?

OR can I access the HPE 1 action script (wich I surmise was written in Photoshop x)and read off the Photoshop steps ?

OR am I too ambitious ?

Richard_Lynch
07-26-2003, 01:26 PM
these are good questions.

a) Can I copy? i don't know that there is anything you can do with actions in PS6 that you need my Hidden Power for. if so, and you need to use a reference, that is ok (this would say something like Play hidden power "this action" in the action steps). Copying the sequence to a new action is a copyright violation. Re-recording, technically is not. conceptually, I leave that up to you. If it is for only your use...the restrictions are far fewer.

b) You may simply need to learn to work with tools a little more in-depth to apply some of the background I have included in the tools, but i DO NOT discourage you from taking the tools apart and learning from them. In fact, the book tells you everything the tools do...my goal was to educate the reader, and the more you learn, the better!

c) am I too ambitious? No. You have the PS6 demo, PLEASE use it to your advantage. All I ask is that you don't do like some already have and run away with my idea claiming it is yours. I can't enforce, and won't. I'd just like to have my ideas help promote my book and free tools...and those that need help will hopefully come and use them. Hopefully everyone benefits. All I want is that I get proper credit for my ideas and effort.

I hope that answers. if you need to we can set up a call to discuss.

Richard_Lynch
07-26-2003, 01:29 PM
Really Digesting

is going to take time. As i say in the intro...10+ years (now 11) and still learning every day. If you take photography before that there are a lot more years (started when I was 9). Can I fit it all in a 300 page book? Do I expect you'll grab every nuance that is clear to me?

You'll probably have to read it a few times at least!

Richard

Claude
07-26-2003, 04:00 PM
i don't know that there is anything you can do with actions in PS6 that you need my Hidden Power for
Oh, but there is!

First it would allow to automate the elimination of the background in large series of micrographs and relieve the strain of watching my "steps"(pun intended)

Second, it would let me peek in the innards of actions and learn how they tick so that

Third, I could risk my hand at creating some, mail them to you and IF they are working well and IF you find them useful, I would be honoured to see them included in one of your future batches(does this settle the copyright infringement issue?)

10+ years (now 11) and still learning
How boring are days without !

Thank you for your help

pmarchant
07-26-2003, 09:34 PM
Glad it worked in the end.

The difference between "clear black" and "drop black", is that clear only removes pure black, whereas drop additionally fades out the "almost pure" blacks. I suspect that your two images may have looked the same, but the underlying image data was just slightly different. In which case the difference blending won't yield pure black.

I don't know why Ctrl+E didn't work, as that is the keystroke for Layer>Merge Down which merges the currently selected layer with the layer immediately below (as long as both are visible).

I've only had Richard's book for about 3 months (and PSE2 for about 4) so I've not digested it all! I find I'm using masking a lot, and the excellent section on saturation masking demonstrates you don't have to use the lasso tool to create masks. Once you understand what the Transparent Blending HP Tools do, making masks gets easier. For example, by using a levels-corrected luminosity separation, a curve, and Transparent Grayscale I was able to create a midtones mask. With different curves I also got masks for shadows and highlights (but now HPT3 provides a quicker way to do these two).

It's also worth playing about with the blending modes. I just created black, 50% grey, and white fill layers, a black to white 0deg gradient layer, and a spectrum 90deg gradient layer. Then tried various combinations of the layers to see what (if any) effect the blending modes have.

Cheers,
Paul.

Richard_Lynch
07-27-2003, 07:04 AM
Claude,

All I mean is that you don't need my tools to do things in PS6. You can do them without. Certainly you should learn from them in any way you find helpful.

I would be glad to see what you've put together when you are done.

Claude
09-10-2003, 10:13 AM
Paul and Richard,

After a first WOW! experience with Paul’s technique, Richard’s comment on the need for both backgrounds to be ABSOLUTELY identical became obvious and my idea to move the microscope stage to an object-free position impractical. The reason is simple: the “dirt” content of the fields is not the same (dirt is a composite of dust, staining remnants and thickness variations of mounting medium).

So I set about to circumvent the problem and came up with the following solution:
-AutoLevels
-Lasso a portion of background
-Select>Similar
-Edit>Copy
-Edit>Paste
-Lasso another portion of background
-Select>Similar
-Edit>Copy
-Edit>Paste
and repeat the same a few times , merge all new layers and apply Paul’s technique.
The few remaining blobs are easy to paint over.

See attachment for result.

Claude
09-10-2003, 04:11 PM
So that is all very nice but time consuming and I risked my hand at recording the whole process in Photoshop 6.The action works beautifully on the image used for recording but eats up nearly everything on another(but similar image)!

See for yourselves

Claude
09-10-2003, 04:15 PM
I most certainly must have goofed somewhere and need help.

Here is the action:

Richard_Lynch
09-10-2003, 11:12 PM
If you are working on the same image every time this might work, but the problem is you may be trying to automate too much of the series. For example, if you are trying to do as described earlier, you might want to make a manual selection and then automate select similar, delete, and assign this to a keystroke. You really can only make useful actions of things that are ultimately repetetive...meaning not only that you go through the same steps, but that you go through the same steps applied the *same way* to every image. My guess from looking at that image is that these things are not shaped exactly the same way every time. That being the case you cannot automate the selection of shape.

Depending on what really needs to be selected and the true difference between the images and exposures, you *may* be able to automate more of this (for example, if all the objects will be darker than the background, if they will all be a particular range of reds, whatever). In looking over the text for the action, it seemed that there were unnecessary steps. If using PS6, you would want to sub out the actual selection (Set Selection
To: polygon
Points: point list
point: 23.977 inches, 18.737 inches
point: 23.977 inches, 18.737 inches
point: 23.684 inches, 18.61 inches
point: 23.644 inches, 18.528 inches
point: 23.601 inches, 18.443 inches
point: 23.561 inches, 18.361 inches
...636 More
With Anti-alias -- which selects exactly the same image area every time based on coordinates) with a Stop, that allows you to do something else (make a manual selection) before continuing (by pressing play). In elements, recording would have to be done so all the parts were separate actions with separate prompts for play.

That help? If I had several images to compare, I might come up with something more clear, but I have only the one image with nothing to compare.

pmarchant
09-11-2003, 07:12 PM
Claude, I can't help with the action (I don't have PS6) but I was able to generate a mask thus:

1. Duplicate the background layer
2. Add a Hue/Saturation layer
>> edit the "reds" and "magentas" to have 100% saturation
3. Use HP to add a curve
>> set the graph to "levels of grey" mode
>> activate the pencil (click the "pencil" icon)
>> click at "input 0, output 0"
>> shift-click at "input 170, output 0"
>> shift-click at "input 170, output 255"
>> shift-click at "input 255, output 255"
(the 170 value is a threshold; you might want to experiment with higher/lower values to find a "better" value and to get a feel for what this curve is doing).
4. Use the HP3 to add a Selective Color layer
>> set the method to "absolute"
>> for the "reds", "magentas" and "blues" set the black slider to +100%
5. Hide the visibility of the background layer; select the background copy layer, and then "merge visible"
6. Reduce the opacity of the copy layer and re-enable the visibility of the background layer.
7. Use a hard white brush to paint over the black blobs in the "dirt" area (don't worry about the other colours, e.g. cyan)
8. Once you've finished cleaning up, use "Drop Black" and "Commit Transparency" to finalise the mask.

Hope I've explained this OK!

I did try using a Threshold Adjustment Layer (which is where I derived the 170 value from), but I found using the curve gives better results.

Cheers,
Paul.

Claude
09-12-2003, 05:32 AM
Richard,
Thank you for an illuminating answer.
the problem is you may be trying to automate too much of the series
Of course that is it!
automate select similar, delete, and assign this to a keystroke
1-How can I do that?(assign an action to a keystroke)
2-By the way can Play and Stop be assigned to a keystroke?
3-What is the effect of anti aliasing in general and in particular for a selection?
4- sub out means exclude?
Paul,
Thank you too.
Fumbling further afield, I think I found a quicker way to deal with the BG:
-Set background color to white
-Lasso BG sample
-ShiftDrag any further number of BG samples(to catch as many variations of "dirt" as possible)
-Select>Similar
-Edit>Clear
-Paint remaining blobs
This cannot be automated but I think it is faster than anything else.

Claude
09-12-2003, 08:14 AM
I forgot to attach a picture

Claude
09-13-2003, 03:27 AM
Paul,
I really must thank you again after trying your last suggestion.
It is a bit involved for my purpose of treating quickly a sometimes large number of images but it also throws a light in the(for me) still dusky lanes of PE and HPE.
I could not have come to the method mentionned in my last post without yours and Richard's suggestions.

pmarchant
09-13-2003, 07:00 PM
Claude,
glad I could help, and I have to say I've found the images of yours quite intriguing to look at.

I find masking does play a big part in image manipulation, and the "clear/drop" HP tools are invaluable in mask generation -- all you have to do is manipulate the image to get to the point where you can use them and you've got your mask. This is where playing around with the other tools helps. Sometimes you get a weird or wacky result, which may be useless in the final image -- but it could be a big help in mask generation! For example the curve I suggested you create is inappropriate for the final image because it destroys detail. However, the simplification of the image it produces makes it ideal for mask generation.

Cheers,
Paul.

Claude
09-14-2003, 04:03 AM
Paul,
I've found the images of yours quite intriguing to look at.

They are 15µm stained sections of wood prepared to help identifying the lumber I find,receive or steal to satisfy my woodturning lust.
An example of my strivings: