|
Hi all,
i am having 12 bit image data in a 2D array. How can i create a 48 bpp bitmap image using actually 12 bits only for pixel color information and the remaining 4 bits to be padded. Should i have to define any color pallete for it in the header? or can i directly enter the pixel values for each Red,Green and Blue by copying the lower byte value in the first byte and the MSB value in the second byte?..IF not...how can i create a Palette. How can i store the pixel color values for each pixel (R,G,B).
At present I am using the following command to create a 48 bpp bitmap
Bitmap b = new Bitmap(Width,Height,PixelFormat.Format48bppRgb);
how can i access the Bitmap byte by byte right from the beginning (not from the data [using Scan0]).. I mean the header.
any ideas or suggestions r appreciated...
thanks in advance,
Suman
|
|
|
|
|
why not use the Scan0? I dont think there's a better way to access the actual memory. If you dont want to lock the bitmap, you can use the Bitmap.SetPixel member function.
there are no facts, only interpretations
|
|
|
|
|
P/Invoke the native GDI APIs you need and use the HBITMAP handle form Bitmap.GetHbitmap . That handle is also the address of the entire block of memory, but to use it you'll need to pin the Bitmap into memory so the GC doesn't move it. See the GCHandle class for more information about locking the Bitmap (which can also get you the HBITMAP you can use).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
The fact that you're putting 16 bits in to specify each colour means that, by default, there is no palette information required.
Why do you need to access the header ?
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
HI Graus,
thanks graus... it seems u r very nice... i thought th u would be vexed by my frequent questions.
Actually wht happened is my advisor asked me to convert those LL1/LT1 format image files to BMP format and he hasn't specified the bit depth ahead..so, i thought of doin the most common 24bit BMP image. But yesyerday, he want me to use all the 12 bits in my original image to create a 48 bit BMP image (16/16/16) by using 12 bits for actual pixel information and padding the reaminin as it was int he original image.
So, now I want to convert the original image into 48 bit bmp instead of 24 bit, which i did now. But, i am thinkin tht it is not the same way as i implement 24 bit for implementing 48 bit. I thought should I have to use any color pallete to do so...
if i am worng, please let me guide into right direction. If u think there is some easy way to do this.. plz lemme know..as soon as possible...
thanks in advance,
Suman
|
|
|
|
|
Suman Somanchi wrote:
I thought should I have to use any color pallete to do so...
Definately not the case. The way a pallete works is that it stores all the colours, then the rest of the image is pallete indexes. It's done to save room, and therefore not done on images with more than 256 colours.
Did you tell your supervisor that Windows cannot display images with more than 24 bits ? You can set it up to be 32 bit, but the extra byte is ignored, it's the same colour count as 24 bit. Also, given that your image is grey scale ( isn't it ), if that is true, then you only have 256 shades of gray to choose from.
Unless you're sending your images to a very funky printer or other device that can handle the bit depth, your supervisor is ignorant. Either way, the most significant bits remain, the difference is going to be very slight.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Hi Graus,
yeah we have discussed on the display issues, but wht he is concerned abt is if we convert it into a 48bit Bitmap then we can reatain the original pixel data and it willbe helpful for some image processing techniques, sothat we can reduce data losses.
I am clear, wht we have thought. Anyway I successfully converted it into 48bit bitmap and displaying its histogram.
thanks for ur advices all the way,
Suman
|
|
|
|
|
Hi Graus,
I am able to produce a 48 bit bitmap... but it seems there are no white greylevels at all in it, it is showing full of greylevels and black...
How can we invert a 48 bit bitmap....do we have to do any shifting operations or can we proced using substraction doe for 24 bit bitmap.
if u have any ideas plz lemme know...
thanks in advance,
Suman
|
|
|
|
|
White is when all the bits are turned on. If you don't have any whites, your algorithm is obviously wrong, or the source image has no whites.
How are you displaying a 48 bit image ?
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I am using a 48bit bitmap handle all the time when i am cerating and manupulating with 48bit bitmap. Coming to displaying the image.. i am sure tht the display shows only 256 greaylevels.. but i can see the difference between the two images, one converted into 24 bit (8/8/8) and the other one 48bit (16/16/16).. becos i think it is due to clipping...in 24 bit we are forcing 12 bit information into 8 bit where we would loose some greylevel info.. but in 48 bit we are not lossin it and the display maps itself to 256 greylevels.
Now I hope, 'm getting all greylevels.
Is wht I am thinkin is right?
thanks and lookin forward to discuss with you on more issues,
Suman
|
|
|
|
|
If what you get is different between the two, your algorithm is wrong. You still can only display 256 grey levels, less than you are trying to put into both images. Therefore, if there's a visible difference, you're doing it wrong.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Hmm... but i don't know how to tell tht the image i am displaying is right or wrong.
here is wht exactly wht i am displaying. I am displaying a radiograph of spinal cord. When i am viewing it in a 24bit format, I can barely see 3-4 vertebrae outlines, but when i display it in 48bit, then there is improvement, now i can see around 4-6 vertebrae outlines, without loss of any of the previous information ( i mean the information which we can see in a 24bit).
Anyway.. how can i crosscheck my code whether wht it is doin is right or wrong..?
Suman
|
|
|
|
|
Suman Somanchi wrote:
Anyway.. how can i crosscheck my code whether wht it is doin is right or wrong..?
Compare it to the original image ?
By the way, you need to be doing some pretty funky image processing to care about those extra four bits. Create a Bitmap object, draw on it in black, and then draw some shapes using the grey level of 1. In other words, the colour is 1, 1, 1. Can you see the shapes you've drawn ? That colour difference is greater than the most significant piece of information you're retaining by going to 48 bit.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
yeah we have to compare with the original image.. but i am not able to display the originalimage as it is in raw format and is of some extension (*.LL1/*.LT1), for which as far as my search, didn't find an editor to display them.
Yep u ar right, we can't view the difference between them and i too agree with it. But, I can't do anything since, I am a student and I have to do what my advisor says.. I am doin this to satisfy him.
But in my opinion... 24 bit images are well suited for humans to perceive the difeerence between all the greylevels and also to display the images.
Suman
|
|
|
|
|
Suman Somanchi wrote:
But in my opinion... 24 bit images are well suited for humans to perceive the difeerence between all the greylevels and also to display the images.
Yeah, well, 256 colour paletised images are equally good, being identical.
Suman Somanchi wrote:
but i am not able to display the originalimage
If your advisor expects you to be able to display an image that you can't even see to compare to, they should be pleased with whatever they get. If you can't see the problem in the code, tell them that you've done it, the 48 bpp looks better, which proves them right, then sit back and suck up the praise. If they're going to ask you to do it a dumb way and not give you the resources you need, then that's as much as they deserve. It sounds like the 48 bit image is the one that you're doing right anyhow, which makes sense as you're starting with 48 bits, it's obviously the conversion to 24 bits that you've screwed up.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Hi Graus,
If u don't mind. I am having another question. How can we draw a 3D surface plot in a c++ program. I am having the three (x,y,z) data generated in my program, but i don't know how to create a plot of them at runtime. I hope we have to create an activeX control to implement tht. But my program is a plain cpp program. At present i am writing all the data into a text file and opening it in an excel sheet seperately and then drawing the graph.
if we have to convert, how can we convert a plain cpp file to activeX and include tht functionality.
if u r familiar with this and r having some ideas, plz share with me...
thanks,
Suman
|
|
|
|
|
Suman Somanchi wrote:
how can we convert a plain cpp file to activeX and include tht functionality.
You want to turn your app into an ACtive X control, or you want it to consume an existing ActiveX control ? How will ActiveX plot 3D for you ? DirectX will, and the DirectX sdk has heaps of examples for you. I don't think you need direct X though, you need to do some reading on 3D math and then you can plot it yourself.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Thanks Graus,
I will try to implement what u told and infact i am little bit aware of tht 2D to 3D geometry in my Computer Graphics course in my undergrad. For today I am stopping my programming, since I want to spend sometime on other subjects too. I will do it tommorow and let u know the improvements...
Suman
|
|
|
|
|
Hello there!
I´m having a problem here.
I have a xml file with many tags, and I only want to add information to one tag "<MediaInformation>". How can I read the file to that especific position and them add the text information "clip1.mpg".
Anyone can help me?!!
Thank you very much
|
|
|
|
|
The number of tags isn't so much an issue as the size of the file (tags names could be small, so the file could also be smaller). The easiest way is to load the document into an XmlDocument , use XPath to find the node, and add your node:
XmlDocument doc = new XmlDocument();
doc.Load("data.xml");
XmlNode node = doc.SelectSingleNode("//MediaInformation");
if (node != null)
{
XmlElement elem = doc.CreatElement("name");
elem.InnerText = "value";
node.AppendChild(elem);
} This is definitely only an example, though, since without knowing more about what you're trying to do I can make too many assumptions. If you're XML documents uses a namespace (typically a good idea if you allow for mixed schemas) then you'll need to use an XmlNamespaceManager , too. You can find more information and examples in the .NET Framework SDK.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
First of all, I want to thank you for your help.
But the problem continues... =/
My XML struct it´s like show below...
<Mpeg7>
<MultimediaContent>
<AudioVisual>
<MediaInformation>
</MediaInformation>
</AudioVisual>
</MultimediaContent>
<Mpeg7>
And I want to add the tag "<name>clip1.mpg</name>" to the media information.
I´m trying to do this way
XmlDocument doc = new XmlDocument();
doc.Load("data.xml");
XmlNode node = doc.SelectSingleNode("//MediaInformation");
if (node != null)
{
XmlElement elem = doc.CreatElement("name");
elem.InnerText = "clip1.mpg";
node.AppendChild(elem);
}
It seams that MediaInformation don´t exist because the program never enter in the if condition.
Do you understand what is the problem?!!!
Thank you very much
|
|
|
|
|
I can't really help you much because you need to encode your XML or check "Do not treat <'s as HTML tags" when posting.
Instead of doc.SelectSingleNode , use doc.DocumentElement.SelectSingleNocde . Sorry.
If that doesn't work, it's probably because your XML document is using a default namespace in which case - like I said in my first reply - you have to use an XmlNamespaceManager and pass that along to SelectSingleNode . Default namespaces aren't supported very well, so use prefixes (prefixes don't have to match the source documents; only namespaces have to match):
XmlDocument doc = new XmlDocument();
doc.Load("data.xml");
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("def", "yourNamespace");
XmlNode = doc.SelectSingleNode("//def:MediaInformation", nsmgr);
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
but I check "Do not treat <'s as HTML tags" !!!
Can´t you see the XML code?!! =/
I think that I´m not using any namespace.
But the node gives always null...
|
|
|
|
|
hello again, I´m trying to find what is my namespace, my xml is like this...
<Mpeg7 xmlns="urn:mpeg:mpeg7:schema:2001" xmlns:xsi="http://www.w3.org.2001/XMLSchema-instance" xmlns:mpeg7="urn:mpeg:mpeg7:schema:2001">
<Description xsi:type="ContentEntityType">
<MultimediaContent xsi:type="AudioVisualType">
<AudioVisual>
<MediaInformation>
you said to use this thing
nsmgr.AddNamespace("def", "yourNamespace");
but my namespace what is?!!
thanks
|
|
|
|
|
You should really read-up on XML. All the "xmlns" attributes identify XML namespaces. Without ":something" after it (a namespace prefix), it identifies your default namespace (the namespace to use when you have no prefix). Therefore, your namespace is "urn:mpeg:mpeg7:schema:2001" and you need to modify my code like so:
nsmgr.AddNamespace("def", "urn:mpeg:mpeg7:schema:2001");
XmlNode node = doc.DocumentElement.SelectSingleNode("//def:MediaInformation");
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|