Skip to content

mikealsim/remove_bw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

This python aplication and library will remove all white or black from an image, prefectly preserving the color and value of the rest of the image. It's based on a previous photoshop plugin I created, call killwhite.

App Supports 8/16 bit RGB images, fastest with 8 bit Library use numpy and expects 3 channel RGB array

How it works

In the case of [127] gray pixel, it finds the amount of white in the pixel (50%), then sets the pixel to black, and adds a 50% alpha. Thus the finnal result apear to not have changed but now has a transparency. 99% black is still 1% white and will have a 1% alpha.

If it affects a reagon your didnt want, use photoshop or another editor and merge the images togeather preserving the areas you want.

The recipe:

RGB -> HSV
convert to double 
convert to value scale (0-1)

// make the alpha
alpha = 1.0-(v-s)

// preserve color and values
if (alpha < 1.0)
  v = s/alpha
  S = s/alpha

to origional value scale
HSV -> RGB

Use RemoveWhite()

It can be used to remove the background from a logo

logo logo_alpha

Add alpha to difficult to edit artwork:

logo logo_alpha

combine with other images / color to replace the white in an image:

white_flower fire_alpha

flower source                       with alpha from RemoveWhite()

white_flower_background

Add background color

white_flower_combined

Comnbine in photoshop, notice how it keeps the origional texture and shadows

Use RemoveBlack()

Stock fire images/video is usualy shot on a black background for ease of adding to other imagery. This makes it even better, no compromise in color or value like with "blendmodes" techniques. This give you full freedom to get the colors you want.

fire fire_alpha

fire source                         with alpha from RemoveBlack()

grill mask

grill source                         aditional mask

fire_grill

finaly combine in photoshop

Parameters

-i, --image

this is the path to the desired image

-a, --alpha_suffix

Optional, Separates the alpha and adds suffix to alpha's filename, without this argument it will write a single file with alpha if the file type supports it. Use this if you want to write a file type without an alpha channel like JPG.

-o, --output

output image path and extension

-b, --remove_black

Optional, With this flag it will remove black, by default it removes white.

--plugin

Advanced, Optional, I use the imageio for increased file type compatablity, imageio has multiple methods to write common file types, use this flag to specify which imageio plugin you want to write with. May require additional installation, see imageio docs for more info. Example plugins: [opencv, freeimage, pillow, ITK, GDAL, tifffile]

About

remove white or black completely from an image

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages