Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

README.md

TransparencyMaker

Transparency Maker reads in a .jpg or .png and creates a Pixel Information Database, that can be manipulated in a language I invented called BQL or Bitmap Query language.

Motivation

The reason I wrote this program originally is when I purchase stock photos, almost all come with a background color and often I need a transparent background. There are other tools that perform background removal, with more now than in 2012 when I started working on Transparency Maker, however I wanted a way to programmaticaly manipulate pixels.

Rebranding the name to Pixel Database

The original purpose of Transparency Maker was to make backgrounds transparent, thus the name. I have now expanded the features to include updating pixels, changing colors, etc.

What do you think? Should I keep the name Transparency Maker, or do you like Pixel Database better?

Let me know by creatiing an Issue on this project, or on any Transparency Maker videos on YouTube.

Visual Studio

Visual Studio 2019 is the recommeneded version, but most of the code worked as far back as VS 2010.

Install Version

I have an install version on my website:

https://datajuggler.com/Downloads/TransparencyMaker.msi

Transparency Maker Videos on my Channel

https://www.youtube.com/playlist?list=PLKrW5tXCPiX2PxrLPszDzlcEZwQG-Qb8r

I just updated my channel to be split into more play lists to separate each section.

How Transparency Maker Works

The first thing that happens when an image is opened, is your file is parsed into a list of PixelInformation objects, aka Pixel Database.

When the program starts, click the Start button to select your image. The image must be a Png or a Jpg.

A Pixel Database is a List of PixelInformation objects that contain properties about the pixel. To find the pixel information for any pixel, turn the Color Picker on.

Tip: To determiine if the Color Picker is on, hover your mouse of any part of your image. If the mouse cursor turns into a pointer (a hand), then the Color Picker is on.

Once the Color Picker is turned on, click any pixel in your image and a Pixel Information Box pops up:

The box contains the following properties:

Red

The Red value of RGB value. Value range is 0 - 255.

Green

The Green value of RGB value. Value range is 0 - 255.

Blue

The Blue value of RGB value. Value range is 0 - 255.

Alpha

The Transparency Level of the pixel. Values are 0 - 255, where 0 is transparent and 255 is visible.

X

The horizontal position of the pixel clicked.

GreenRed

The sum of Green plus Red.

BlueGreen

The sum of Blue plus Green.

BlueRed

The sum of Blue plus Red.

Total

The sum of Red plus Green plus Blue.

Y

The vertical position of the pixel clicked.

You can use all of the above values in your queries to manipulate your image.

BQL - Bitmap Query Language

Why BQL?

This application started out as a plain Windows Form that I would hard code C# statements to replace the background of stock photos with transparent backgrounds. Over time I switched to a more object oriented approach where I analyze the entire image, and thus the Pixel Database was created.

The initial criticism I have received is there are not any controls like most graphic programs. If that is what everyone still wants I am open to ideas about what types of controls are needed. I created BQL because it is similar to SQL that many C# developers already know, thus enabling them to get up to speed quickly. Another reason I created BQL instead of a control based graphical UI is time to develop. Many of my failed endeavors have involved very complicated UI's, and then I am reminded of this small company called Google that started with a webpage that contained a single textbox and a button.

Hide / Show vs Update Queries

There are two types of queries; Hide/Show and Update.

Hide / Show

Hide

Any pixels affected by the query will be set to Alpha 0, which makes them invisible.

Example

Hide Pixels Where
Total > 700

Shortcut: Hide

Hide Pixels Where can be shortened to:

Hide
Total > 700

Show

Any pixels affected by the query will be set to Alpha 255, which makes them visible.

Example

Show Pixels Where
Red < 200

Shortcut: Show

Show Pixels Where can be shortened to:

Show
Red < 200

Important

This query parser may be rewritten to be more robust someday, but for now certain attributes must be on their own line. I wrote the query parser in a few hours many years ago, and it works pretty well so I have not bothered to refactor it (yet).

So the query above would fail if written like this

Invalid

Show X < 150

Correct

Show
X < 150

It wouldn't be that hard to rewrite the query parser, so let me know if you think the line by line requirement is confusing. I know it is crude, but this app was designed to be quick, dirty and functional at first.

Operators

Equals

Equals Symbol: =

Will match criteria on exact values.

Equal Example:

Hide
Red = 233

All pixels that have a Red value of 233 will be set to Alpha 0 to be hidden.

Greater Than

Greater Than Symbol: >

Will match criterian on greater than or equal to

Greater Than Example

Show
Y > 1200

All pixels with a Y value of 1,200 or higher wil be set to Alpha 255 to be shown.

Less Than

Less Than Symbol: <

Will match criteria on less than or equal to

Less Than Example

Hide
BlueGreen < 300

All pixels with a BlueGreen value of 300 or less wil be set to Alpha 0 to be hidden.

Between

Will match criteria that is greater than or equal to the first number and less than or equal to the second number.

Between Example

Hide
Blue Between 200 255

All pixels with a Blue value between 200 and 255 will be hidden.

Compound Statements

You can combine criteria to further narrow down the pixels that are manipulated

Important: Each criteria must be on its own line.

Coupound Examples:

Show
X > 200
Y Between 112 140
Total = 765

All pixels with X coordinate of 200 or higher and a Y value of 112 - 140 and a Total of 765 (White).

Update Queries

Update queries are very similar to Hide queries, except that you must include a Color attribute

Set Color

There are two ways to set a color, Named Colors or RGB values.

Named Color

You can set a pixel to a named color

Note: For a list of Dot Net Colors see System.Drawing.Colors or this website lists them: http://www.flounder.com/csharp_color_table.htm

Named Color Example

Update
Set Color FireRed
Where
Total Between 125 150

Note: Where must be on its own line for Update queries

RGB Color

You set the color by specifying the Red, Green and Blue values

RGB Color Example

Update
Set Color 121 220 7
Where
Y > 100

Where is not optional

You must specify the Where, even if you want to update all pixels

Update
Set Color White
Where
Total > 0

Note: In the above example, all pixels will be set to white, since greater than > is equal to > or equal to.

New Feature: 2.22.2020 - Added Adjust color feature

The adjust color feature lets you adjust 1 color (Red, Green or Blue) or all colors by a certain amount.

Example: Update Set Adjust Red 25 Where Total > 0

Negative Color Example

The Adjustment value can also be negative.

Update Set Adjust All -15 Where Total > 0

All pixels will be adjusted by 15, so Red = 33, will become red = 18.

It is safe to apply a value as if a color channel of a pixel goes over 255 the value will be 255, or below 0 will be 0.

New Feature 2.23.2020: Swap (color)

I added a new useful feature called Swap, that let you replace the value of Red With Blue, Red With Green or Green With Blue, and of course the opposite of swap is the same; green to blue is the same as blue to green.

Swap Example:

Update Set Swap Red Blue Where Total > 0

The above query will replace the value of Pixel.Red with Pixel.Blue for all pixels in the image (again greater than > is the same as greater than or equal in BQL.

Swap is safe to use, in terms of if you have a pixel with a vlue of blue 30, and you subtract 50, the resulting value of blue will be zero, not -20. The same is true for adding over the max value of a color (255), the value will be set to 255. One problem with swap and values going out of bounds is the contrast created by slight variances give an image a different look, compared to all pixels being the same color. Some information in your image will be lost if you go below zero or above the maximum for many pixels.

New Feature 2.23.2020: Masks

Masks is something I have thought about for a long time. Today I worked on a sample and some unwanted pixels kept getting modified with my query, so I got motivated and created a new property to the PixelInformationObject called Mask.

Mask Rules (This is the my guide for programming them, and is created as I code this).

Masks will stay on after being created until you load a new image, remove the mask, clear all masks or close the program.

Masks only affect Update queries for now. Hide Pixel and Show Pixel and draw line queries are not getting this feature (yet). If it works well I may apply it to the other areas later.

Mask Specification

Set Mask Verb Name

Verbs

Verbs are actions that can be performed to create, add, remove or replace masks.

Add

Add a mask and give it a name.

Example: Set Mask Add Interior

Replace

Replacing a mask removes all pixels affected by a mask, then creates a new mask for the pixels affected. Example: Set Mask Replace Mailbox

If any pixels had a Mask applied named Mailbox, they would be removed, and then a new mask named Mask Mailbox is created for the pixels affected in the update query.

Clear

Remove a mask by name.

Example: Set Mask Clear Fence.

Clear (All)

To remove all masks, pass in the name All.

Set Mask Clear All

Note: Clear and Clear All may require you to still pass in a valid where clause. If yes, You can use:

Update Set Mask Clear Curb Where Total > 0

When I start testing this I will try and document what is actually expected, and if possible I would like to get rid of the required Where clause. It should mean everything from the Select like SQL.

Disabling a Mask

If you want to keep a mask on an image, but want to run another query where the mask isn't active (disabled), you can run this.

Set Mask Disable Bookshelf

To enable the query again:

Set Mask Enable Bookshelf.

Hiding / Showing a Mask

By default, Masks are not visible, but a query to show them is as simple:

Show A Mask:

Update Set Mask Show Name

Hide A Mask:

Update Set Mask Hide Name

Set Mask Color

By default, Masks are displayed in White. You can change this by setting the MaskColor property.

Set MaskColor Color Name

Color must be a .Net Named Color. If you are not sure, use the small box of Crayon colors like Red, Blue, Orange, etc. Name is the name of the Masque to set the MaskColor.

Example: Set MaskColor Turquoise PianoKeys

Note: You must set the MaskColor property prior to showing the Mask.

Masks Are Being Developed Now

I needed to write this somewhere to code it, and by writing it here first I don't have to come back and write it again.

Normalizing An Image

One of the uses of Transparency Maker is an image that is grainy or pixelated, you can smooth out an area by setting all pixels in a range to a certain value.

Update
Set Color 220 0 55
Where
Total Between 525 590
X Between 200 360
Y > 400

Drawing Transparent Lines

To Draw a Transparent Line, Type The Following

Line 1: Draw Line LineThickness
Line 2: First two points are Line Start Point X Y
Second two points are Line End Point X Y
Line 3 (Optional): Repeat Direction Iterations Move

Draw Line 4
161 125 457 66
Repeat Down 15 1

Tip: Line 2 can be filled in for you using the Color Picker

Type Line 1 Draw Line (Thickness), then hit enter to place your cursor on the next line. Ensuriing the Color Picker is toggled on, Click on your image to establish Point 1:

Draw Line 4
161 125

Then click your mouse again for the end point of the line:

Draw Line 4
161 125 457 66

(Optional) Type line 3 if you want to repeat.

Then click Apply.

Draw Line 4
161 125 457 66
Repeat Down 15 1

Repeat Directions

Use with Repeat with Down, Up, Left and Right

Repeat Up Example

Draw Line 2
0 64 457 66
Repeat Up 100 2

The above line will be drawn 100 times, and each time it will move the Y coordinate up (minus) two pixels.

Note: The line will go futher than the bounds of the image, so Repeat 50 would accomplish the same thing.

Repeat Left Example

Draw Line 1
225 412 105 430
Repeat Left 25 2

The above line will be drawn 25 times and will move the StartPoint.X and EndPoint.X left two pixels each iteration.

Repeat Right Example

Draw Line 5
140 300 90 600
Repeat Right 50 10

The above line will draw transparent stripes through an image because the Repeat Move (last parameter) is greater than the line thickness from Line 1.

Draw Transparent Lines Are Slow In Large Images

Drawing transparent lines is slower than any other operation using Transparency Maker because what it actually does is create a copy of the source image and draws a line trhough the copy in a color that doesn't exist in the copy, then creates a Pixel Database out of the copy image and determines which pixels were modified. The pixels that were modified in the copy are then applied to the source Pixel Database and set to Transparent.

I think this is a good candidate for letting people with a powerful GPU take advantage of this, but I haven't learned how to apply this yet. I have a 1080 TI, but I have never written any code to take advantage of a GPU. Volunteers anyone?

Masks

Known Issues

Clicking Save sometimes causes an error. You can think click Continue, and are returned to your image. Click Save As works.

Upcoming Features

It has been on my list for a long time to add a Save prompt if there are changes and you attempt to close the file or the application.

Let me know what features you think are needed or any feedback you may have.

Draw Line In Color

I thought I had code to draw a line in a specific color, but this has not been done yet apparently. It will be coming soon.

If anyone wants this feature let me know.

Any suggestions or feedback is welcome.

About

Transparency Maker reads in a .jpg or .png and creates a Pixel Information Database, that can be manipulated in a language I invented called BQL or Bitmap Query language.

Topics

Resources

License

Releases

No releases published

Packages

No packages published

Languages