For microscopy purposes, I am trying to plot the black to white pixel density on an edge of an object(cell, quantum dot etc...).

What algorithm could I use to calculate the pixel density of an object in an image? 

I know I would need to draw a line through it some how.. from there I'm lost. 

I have about a year of experience in the Python language so i should be able to understand most of what anyone can hopefully throw at me!

Any input will be highly appreciated!