Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am not entirely sure if this can be done but I need to ask the question.

In an application I am working on, at one point I have an option to take an image and do edging (embossing) on it with the Sobel transform algorithm.

Now the result is a typical a black and white image. I was wondering if one can convert a range of "white" pixels to be transparent. The idea behind this is to use the edged image and place it over another to compare artifacts on both of these images.

For example, I want to see if an artifact is getting bigger or smaller when I have an image of say 3 month back and a more resent image.

So basically I want to be able to overlay one image over another where the white pixels of the top image is transparent. All the images I work with are .jpg files with a size of approximately 2.6 mbyte.

Regards,

Tino
Posted
Comments
Sergey Alexandrovich Kryukov 24-Apr-14 18:00pm    
It depends on what you are using. System.Drawing? WPF? Anything else? Why not reading standard MSDN documentation?
And the result of embossing should not be white and black. You are doing it wrong. And it should not be transparent; therefore, I see no reason in helping you doing the transparency.
—SA
Tino Fourie 24-Apr-14 18:39pm    
Sergey, thank you for your reply. I prefer to use System.Drawing / GDI+ and not jump to WPF since I am not very familiar with the code. As for reading through MSDN documentation, unfortunately I do not understand half of what Microsoft writes in their technical documentation and I find their example code to be more confusing than anything else and in other cases I can't apply their examples to my problem. It is for this reason I visit websites like Code Project and Stack Overflow, maybe this is the reason why these websites exist in the first place.

As for my choice of doing a Sobel transform, I prefer to have a more black and white image and since I have 18 (9 for the X-axis and 9 for the Y-axis) values to manipulate between the values of +5 and -5. I think I have earned the right to choose how light or dark my transform gets done since it is my application and most certainly not yours.

Of everything you wrote in your reply, the part most striking is what YOU decide what can and can't be transparent. I think I made it perfectly clear why I need to convert a range of white pixels to be transparent. In addition, I fail to see who gives YOU the authority to decide what can be done and what can't be done in other people's application.

Lastly, if YOU see no reason to help then why did you bother to post unless ofc you are trying to bump up your reputation score with meaningless comments like you have done here.

You should really try to keep your opinions to yourself and stop posting on threads where you do not wish to help. If you have something to contribute then post your contribution else don't bother to even leave a footprint that you have visited this page next time.

I hope you have a fantastic day ahead of you.
Sergey Alexandrovich Kryukov 24-Apr-14 19:16pm    
I did not decide anything, but you did not explain anything. Nevertheless I already started to type detailed answer on the use of System.Drawing and transparency, but later saw your words about "trying to bump up your reputation score with meaningless comments", which is rude and plain stupid. And this is in response to some mild criticism not touching your personality. Shame on you.

After that, I unfortunately have to conclude that you are not the person to deal with. Why would I bother? The problem is simple enough, so you can dig in documentation just a bit to find out how to solve the problem. And I would advise you to never tell members what to comment and what not. If you allow yourself your rude comments, why would you expect others not posting something which is merely pointless, in your opinion? People are equally free here.

Sorry for changing my mind and not helping you. Have a great day.

—SA

P.S.: And sorry for not participating in any further discussion.
Tino Fourie 24-Apr-14 20:00pm    
I am truly fascinated by your way of giving mild criticism not to mention the fact that you accuse others of being rude while you at the same time are very forthcoming with your opinions and so called mild accusations.

If you are unclear about the question, you "ask" for clarity, not give your opinion. Allow me to quote a valuable quote from Code Project:
"3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome."
Am I missing the part where it is mentioned to give your opinion without substantiating it or why you have come to that conclusion ?

Allow me to quote your first post:
"And the result of embossing should not be white and black." Says who exactly? The Sobel transform is dynamic enough to allow for different results. There is no industry standard for a Sobel transform therefore any result can be accepted, it does not mean it is the best result.

"You are doing it wrong" Says who exactly ? Refer to previous comment.

"And it should not be transparent". A Sobel transform does edge detection, nothing more. It is therefore safe to say that a Sobel transform's intended use is not to create transparent areas on an image.

"I see no reason in helping you doing the transparency." And yet you have prepared a detailed answer. You are opinionated, easy to "mildly" criticise others and contradict yourself. You sir, have no contribution to make here except for your opinions, contradictions and criticism without substantiation.

Please, continue to have a fantastic day.

Although I am not a graphic artist by any stretch of the imagination, it appears to me that I may have a better grasp of the intent behind the question. I am drawing on my occasional need to compare and/or overlay two images, although usually by way of a mask. My most ambitions application was dynamic generation of names, email addresses, and phone numbers as grphics files with nearly identical foreground and background colors. By making the background color transparent, the image could be displayed on a Web page that a human could read, but would be much more challenging for a robot to harvest for email addresses.

Anyway, long story short, GDI+ colors have a 4th color attribute called the Alpha channel. Whereas the other three attributes are the standard RGB color codes, the Alpha channel codes affect the transparency of a color.

It's been about 5 or 6 years since I wrote that image generator, but my recollection is that I enumerated the colors in the images's palette, and set the alpha channel of the background color to 0x00 (100% transparent).
 
Share this answer
 
Comments
Tino Fourie 28-Apr-14 9:25am    
Thanks Enigmatic Texan for your suggestion.

I am familiar with the Alpha channel (aRGB) and how to use it. Although I haven't tried it, as I am busy with other slightly more critical functions, I think the problem will come in where it is necessary to filter through a range of different "white" pixels based on the 255,255,255 RGB channels.

In addition to this, I need to try and stay away from a multipass process where I have to scan the image for the various "white" pixels. I might have it wrong due to the lack of research on my part, but as far as I know you can only set one colour a your transparent background.

Coupled with that I will probably need to have an option to set the opacity or at least have control over it from the GUI.

BTW. love the the way you prevented bots from harvesting information ;)
In a 24 bit palette, where transparency is a flag bit, you can have only one such color. That's the beauty of the ARGB colors; since they are 32 bit colors, theoretically, you can set the transparency of each pixel independently. The problem arises when you convert your image to a JPEG or GIF format, both of which have much more limited color palettes. JPEG supports all 16 million colors of the 24 bit RGB triad, but GIF has a fixed palette of only 256 colors.

As a side note, how do you think Aero works; so far as I can tell, it is based on GDI+, which supports the 32 bit ARGB color space.
 
Share this answer
 
Comments
Tino Fourie 4-Nov-14 6:53am    
Once again, thank you for your post.

If I am not mistaken, PNG is the only format that is capable of giving a transparent channel. On this topic, in your experience would it be possible to convert a JPG to a PNG format and then apply the A-channel ?
I think you are correct, although GIF allows you to mark a color in the palette as transparent. In any case, if you load the JPG into a GDI+ Graphics object (in the System.Drawing namespace, I believe), you should be able to convert it into any other format.

However, most of my experience in this regard involved GIF files and palette transparency.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900