For example, using a shape with 2 different opacities.

Add a layer mask for the shape
Select all the pixels of the shape, copy
go in the alpha layer channel and create a new alpha layer, paste

to get the amount of pixels, just use the magic wand as before (on the alpha layer with all other layers invisible) . The trick is that transparent pixels become opaque so only then you can select them.