Is there an issue with transparent png using WhitespaceTrimmer plugin - imageresizer

When I try to trim an image that has a transparent background using the WhitespaceTrimmer plugin i end up with a 3x3 image with nothing in it.
However when I save my source image in paint and the transparent background becomes a solid white background the WhitespaceTrimmer works great.
Am I doing anything wrong which would make the trimmer not function on my original image or is this some sort of bug or unsupported feature?
Original source:
Output of original source (there is a 3x3 image there somewhere):
Original image saved with a white background (using MS Paint):
Output of white background image:
Test Code used to output image through asp.net
Response.Clear()
Response.AppendHeader("Content-Disposition", "attachment; filename=testSigOutput.png")
Response.ContentType = diFunctions.getContentType("png")
ImageBuilder.Current.Build("C:\Solutions\TestImages\testSig.png", Response.OutputStream, New ResizeSettings("trim.threshold=80&trim.percentpadding=0.5"))
Response.End()
Edit: I did some additional testing, I have come to the conclusion that when it converts the image to grayscale it is treating transparent pixels as black.
Regardless of what color I set the transparent background pixels to it will not work.
However if I change the pen color or make the background slightly visible (0.01 alpha) it works fine.
So the answer is I have a work around but is this working as intended?

WhitespaceTrimmer converts images to grayscale so that an energy filter can be applied. It's likely that your image turns into a black square when converted to grayscale. To test this, try making the figure in your image a different color (but still against a transparent background).
Another possibility is that the transparent pixels in the image are of the same color, and thus the outline only exists in the alpha channel - which is not multiplied against the other channels.

Related

How to cut the png image as per the shape?

I have no experience on any image processing/editing tool. And I am doing a project, which requires me to use different shapes. I could create different shapes using visio. But however not able to get rid of white background behind. I need only shape not squared white background.Tried online out of my ways but not successfull.
Any help will be greatly appreciated.
Thanks,
Ganesh
Absolutely any image file has to be contained within a rectangular frame, this includes png and SVG.
Some image file formats can have what are called alpha channel backgrounds this allows you to see through transparent areas.
What you want to do is remove the white background to expose the alpha channel background in Photoshop (or similar tool) which can then be saved out as transparent.
For example in Photoshop:
If you open this image directly and have no other layers, double click the layer that says background and OK the confirmation box. This turns your flat image into a layered image
Select the magic wand tool and ensure you have a high tolerance set (3)
with the wand selected click the white area to bring up a marquee around your selection (the white background) and hit delete to remove it.
Your image should now have a chequered background which is the transparency showing through.
If you now go to file > save as and select png, your image should now be saved out with an alpha background.
Please note: There are further optimisations to make if this is for web, including file formats and file size but that is beyond the scope of this question but I encourage you to read up on the Gif format and it's restrictions, the difference between 8bit and 24bit pngs and how to use SVG.
You can do it pretty simply at the command-line using ImageMagick which is free and installed on most Linux distros and is available for OSX and Windows.
Basically, you want to make your whites transparent, so you would do
convert shape.png -transparent white result.png
If your whites are a little bit off-white, you could allow for some variation with a little fuzz as follows:
convert shape.png -fuzz 10% -transparent white result.png
I added the checkerboard background just so you can see it on StackOverflow's white background - it is not really there.
By the way, you may like to trim to the smallest bounding rectangle while you are there:
convert shape.png -fuzz 10% -transparent white -trim result.png
By the way, you can also draw your shapes with ImageMagick:
convert -size 150x150 xc: -fill none -stroke "rgb(74,135,203)" -draw 'stroke-width 90 ellipse 0,0 80,80 30,80' arc.png
See Anthony Thyssen's excellent examples here.

Images appear "washed out" based on background color, using EMGU Camera library

I'm using the EMGU CV .NET library. I noticed that when I take pictures of anything with color, the colors usually get "washed out" if the background is dark(ish). General rule of thumb I've found is that, the darker the background is, the more washed out the colors are.
Here is how I'm retrieving the image from the camera with EMGU.
Dim imgFeed As Bitmap = mCamera.RetrieveBgrFrame.ToBitmap
In the images below (cropped out some of the background on both), the left image is on dry white cement and the right image is on wet white cement. You can see the "washed out" color especially on the first tag, which is bright orange duct tape.
Here is another image, taken on black pavement in the sun, which in reality is much darker than the white cement, but appears similar in color to the background in the wet cement image above.
Is there some sort of auto-balancing that's occurring in the EMGU library? If so, can I stop this from happening? I need to see the colors more clearly than the background. I've read about _EqualizeHist() and I implemented it, but that did not help me see the colors any more clearly; adding contrast to the image didn't really help because the colors were already close to white.
Update
After reading Spark's answer, I found the SetCaptureProperty() method. I see that you can disable the auto exposure property by setting the value to 0 as shown below.
mCamera.SetCaptureProperty(CvEnum.CAP_PROP.CV_CAP_PROP_AUTO_EXPOSURE, 0.0)
Sadly though, with the particular camera I'm using, it looks like the driver does not support changing this property.
This is nothing to do with the algorithm. It is the behavior of Auto Exposure (AEC) algorithm running inside camera chip. Try disabling auto exposure control of camera and reduce the manual exposure level.
Little theory: Most of the AEC algorithm works with full frame weighted method. So in the sample which you showed for white washed case, the black background occupies more portion of the image, which make AEC algorithm to assume that the image is too dark and hence increase exposure level internally.

PNG image opacity not working in browser

As you can see here the screenshot in photoshop:
After I save it for web, using PNG-24 format this is how it looks like on my website:
Why isn't the image opacity working on my browser? Using firefox.
Actual PNG :
I'm not really sure what your desired effect is, but I think that you want the gradient to disappear at the bottom. With that assumption, the problem with your gradient is that it fades from your brown color at the top to white at the bottom.
Your gradient looks something like this:
You want to change the color on both sides of the gradient to be the same brown color, then reduce the opacity of the right-hand side to 0%, like this:
I've adjusted it for you already, so here it is:
It doesn't look any different on a white background, but when it is on another color or texture you'll see the difference.
Does your Photoshop layer have some effected added to it? I.e multiply etc. That would mean the layer is dependant and effected by what is below it.
I face same kind of problem long years ago. when we save our file or image for web. it should be save as web & when we save in PNG format make sure that all background layers off. then just save as web & select PNG(24) from setting option.
& Yes Make sure that where you past the image in web must have CSS in the tag.
background-color:none;

Removing background from the sprite

I'm trying to "load" some 2d image as a material for a mesh, (I know about spritemanager) but I'm unfortunately getting this sprite with it's white background. How can I "make it go"(the background)?
Thanks.
If the image is of a file type that supports transparency, open it up in image editing software (paint.net, photoshop, etc.) and delete the white or replace it with empty/transparent color.
Otherwise, look for an option in the unity documentation to set a specific color value as 'background' or 'transparent' so that that color will be ignored.
First of all, you need to add an alpha channel to your texture and save it in a format that supports alpha channel transparency.
Here is a quick tutorial on how to do this in GIMP:
Note that you can remove the selected background with the Delete-key.
In my case, I'm exporting the result as a PNG for alpha transparency support. You can do this from the export menu by renaming the file suffix to .png:
I use these settings to export my PNG:
Then, after importing the image into Unity, Make sure that in the texture's import settings the image's alpha source is set to Input Texture Alpha and that Alpha is Transparency tickbox is checked like so:
Finally, since you are using this on a mesh, you need to ensure that your mesh has a material applied that has it's render mode set to Cutout:
Hope this little guide helps.

How can I make image brighter (more light as flash effect) using Core Graphics

How can I get flash effect for images got from Camera?
After I got image from camera (it shows in UIImageView) and before saving it as a file I'd like to lighten (in some cases) image by pressing Flash button. Is it possible by using Core Graphics ??
Have a look at my answer to this question. That question was about making an image darker, but you could use exactly the same code and make the image lighter by overlaying a partially transparent white color:
//draw a 50% white overlay
CGContextSetGrayFillColor(cx, 1.0, 0.5);
CGContextFillRect(cx, imageRect);