Remove image solid background with c sharp - c#

I'm trying to find some info about removing an image background "automagically" if possible in .NET.
Actually I could not find much data and I don't event know if it's possible or are there any API components available.
Any ideas?

Establish a rule, for example that the pixel at [0,0] must be the 'transparent' color (the background). Load the image as a Bitmap (let's call it bmp), and then do something like this:
bmp.MakeTransparent(bmp.GetPixel(0, 0));

Homer, for the file formats you suggest, there is no easy way of defining what the 'background' is. For instance, say you have some colorful text on a white background. I'm assuming you'd want to make the white transparent? There is nothing in the file format to say "this layer or color is the background". There may be heuristics for trying to determine the background color, but there will probably be no library to do something like image.MakeBGTransparent().

Related

OpenCV C# - Detecting simple object in static image

I have no experience with images. I have to detect simple object in static image. For example I have image like:
I want to detect edges and remove background. Just to compare them.
Something like this.
Do u have any solutions of this problem? Images have often white backgrounds.
I've just thought about detect edges, and take everything what they contains.
To segment out the shoe-
Anadptive Threshold to remove the smooth changing background.
Sobelx, which removes the apparent background line, which i assume is
common for images of this setup.
dilate, closing operation to separate out the shoe.
Find contours, bounding box etc as per your choice.
Do an additional threshold if you want to remove the shadow at the bottom.

What type of image filtering/processing do mobile PDF scanners use to convert a captured image into a monochrome/black and white image?

I am trying to implement my own monochrome/black and white filter in C# to scan text documents. My approach is to apply a threshold filter on the captured image. However, I often run into the problem that the varying brightness on the image causes a ''shadowing effect'' on the processed image. Refer to the link below (it is pretty blurry but it should suffice). The image to the far left is the original image. When I apply my threshold filter, I get the same result as the image in the middle; some of the text becomes unreadable because the brightness of the image varies, so some portions become really black or really white. However, with the right filter, you can obtain the processed image to the right where everything looks crystal clear.
https://www.google.dk/search?q=monochrome+image+processing&espv=2&biw=1706&bih=859&source=lnms&tbm=isch&sa=X&ved=0ahUKEwir8vXlhIzPAhUFiywKHeSBC1wQ_AUIBigB#imgrc=4UTzoIpyqTkwrM%3A
I would like to know what the process is to obtain the image to the far right. Another example can be seen in the image below. It shows a sample mobile PDF scanner in use. Scanning the image results in a very nice black and white image, where the text can be easily read and no ''shadowing'' occurs on the image. Does anyone know what this process is or what it is called? It is very often used in mobile PDF scanning applications. Thank you in advance.
EDIT: The filter is called ''Adaptive Thresholding''. You can use the BradleyLocalThresholding class to implement the filter, or you can write it yourself (which is what I did). Please refer to my response to the comment by Yves Daoust down below.
You need two ingredients.
One is "background reconstruction", i.e. retrieving the intensity of the white sheet "under the characters", for instance by morphological opening.
The other is "shading correction", i.e. compensating the unevenness of the background illumination by comparing to the reconstructed background, for instance by subtraction.
This will "flatten" the image, making it perfectly amenable to global thresholding.
A simple method is to convert the image to grayscale and then convert it to B/W using an error diffusion algorithm such as Floyd–Steinberg dithering.

How to transform bmp into table (formatted txt, xls) with rgb values?

I am analyzing an image, with main problem being determining the brightness of an object and contrast between it and background. However, due to object having cell-like structure, with lots of internal spaces with background in it, pixels with background color make too much of a way into selection I use to determine brightness, spoiling the result.
I want to filter all pixels with backfround color out of selection altogether and, since picture-analyzing tool I am using (imageJ) does not allow it, filtering coresponding pixels in table seems to be a rational course.
Using c#, how can I accomplish this task?
Alternatively, any existent solutions would be welcome
Got it done with System.Drawing.Bitmap.

Hiding certain channel of an image with C#

i have an image processing application that is able to getpixel, anyone know how can i hide or show the RGB channel of my image? For example when i click a button call "RED" it will hide red channel and show only blue and green. i m using C# btw
thanks alot
Try the AForge.NET library. Use the AForge.Imaging.Filters.ChannelFiltering filter.
Allocate a blank image (1 channel) of the same size as the original image. Then, when handling a button press for RED, do the following:
split your original image into R, G and B
compose a new image using blank, G, B (in that order, as the order of channels is important). This leaves out the red channel
display the composed image
Handle button presses for BLUE and GREEN in similar fashion.
split, compose and display methods are common in imaging libraries. Their exact names may differ depending on the library you are using, but their overall functionality should generally be the same. By the way, what library are you using? You didn't mention it in your question.
If you're not using any library to achieve what you're doing, you will have to write your own split and compose functions (or something along those lines). You would have to say more about the data structures you are using to get help in that direction.

How do I create a colour that will match the current visual style?

For our winforms application, we've been asked to colour invalid cells in a DataGridView in a red colour. We need to find a red colour that matches the current visual style but which is still distinctive if the user has chosen a palette with mostly reds. How do I create a colour that will match the current visual style? How do I make sure I avoid clashes?
I don't think the original poster is looking to make a palette of colors (colours), instead he is trying to highlight an invalid cell. The chosen highlight color is red, but he is concerned that red might not stick out if the user has chosen a red palette.
How about this: When painting an invalid cell, use SystemColors.Window for the text and SystemColors.WindowText for the background. (or whatever equivalents there are for a DataGridView). This way, you are guaranteed that the invalid cell will be the opposite colors of a normal cell.
I think that you are looking at this the wrong way. Red is often chosen for several reasons. It is (in western culture among others) commonly used to depict that something is wrong or danger. But red is also a colour that usually stands out. However, when trying to direct a users attention to something on the page, there are two infallible methods.
1) Animated gifs or videos (annoying as f***) or
2) Clashing colours
Usually red stands out, but in your situation where a user may have a red themed style, your best bet is to go with a colour that will clash. It is possible to have clashing colours that go together (if that makes sense).
Here are a few websites that I have used in the past to help me find colour schemes that may help you as well:
Kuler, Color Combos and Color scheme designer
This may not have been the answer you were looking for but i hope it helps
The question is a bit ambiguous and a little subjective; it much easier to comment directly on examples. However, there are a multitude of on-line tools that will help you create colour palettes for websites, and these may be useful to gauge how a particular shade of red interacts with various other colours.
Hope this helps.
You could maybe try to use the Light and Dark methods of the ControlPaint class? I do something similar, although kind of in the opposite direction. I needed to make some rows in a grid stand out, but not stand out as much as the selected rows. So I created a color that was a bit lighter than the default selection color like this:
checkedColor = ControlPaint.Light(grid.DefaultCellStyle.SelectionBackColor, 1.65f);
Could try to use that, maybe with some added logic, and base it on some system color that is made to stand out. For example System.Drawing.SystemColors.HighLight or System.Drawing.SystemColors.HotTrack.
take a look at the Krypton Toolkit (http://www.componentfactory.com). They offer a free toolkit for WinForms controls with a theme manager. This theme manager provides ready to use methods to extract the current color values.
I have nothing to do with them. I use it for my own Product (Royal TS at http://www.code4ward.net) and found it really useful.
If you want to build beautiful UI, you should take a look at the Krypton stuff.

Categories