mre2mre
 Advanced Member Posts:34

 |
| 2008-02-11 10:59 AM |
|
hi i use clearcanvas.dicom libary in my c# project
DicomFile _dicomfile = new DicomFile("SampleFile.dcm"); _dicomfile.Load(DicomReadOptions.Default); byte[] pixelData = (byte[])df.DataSet[DicomTags.PixelData].Values;
how can i convert pixelData to System.Drawing.Image object or jpeg? thanks for your help
emre
|
|
|
|
|
norman
 Senior Member Posts:811
 |
| 2008-02-14 12:27 AM |
|
Hi emre, There is no means of converting the pixel data to a System.Drawing.Image or JPEG using the DICOM toolkit. (For reasons that I won't get into here, this is by design.) The process of rendering pixel data to a bitmap is actually fairly involved, as it requires that you deal with the various combinations of photometric interpretations, bits allocated, bits stored, planar configuration and pixel representation. In the case of grayscale images, you also need to create lookup tables which account for window and level. If you don't mind adding dependencies other than ClearCanvas.Dicom.dll to your project, you should be able to use ClearCanvas.ImageViewer.dll to help do this for you. Although I haven't tried it, I think this might do the trick: LocalImageSop sop = new LocalImageSop("MyFile.dcm"); IPresentationImage image = PresentationImageFactory.Create(sop); Bitmap bmp = new Bitmap(width, height); Graphics g = Graphics.FromImage(bmp); IRenderingSurface surface = image.Renderer.GetRenderingSurface(null, width, height); surface.ContextId = g.GetHdc(); DrawArgs drawArgs = new DrawArgs(surface, null, DrawMode.Render); image.OnDraw(drawArgs); drawArgs = new DrawArgs(surface, null, DrawMode.Refresh); image.OnDraw(drawArgs);
Basically what you're doing is creating a device context from a bitmap then getting the renderer to render to that DC. Once you have your Bitmap, you should be able to use .NET methods to convert it to JPEG.
We're eventually going to add a helper method that encapsulates that last chunk of bitmap code so you don't have to write it yourself.
N.
|
|
|
|
|
mre2mre
 Advanced Member Posts:34

 |
| 2008-02-14 02:48 AM |
|
thanks for your reply, i asked this question because i want to write web viewer for clearcanvas regards
emre
|
|
|
|
|
stewart
 Senior Member Posts:2033
 |
| 2008-02-14 10:55 AM |
|
Hi emre, Congratulations! We would love to see someone successfully implement a web viewer with the CC framework. In order to render a Dicom image to a bitmap, Norman's example would definitely work. However, to implement a web viewer, ideally what you would do is write a custom view plugin for the ImageViewerComponent (see ImageViewerComponentViewExtensionPoint) that can be embedded in a web browser. ActiveX or Silverlight would be the obvious choices. In order to do this, though, you would need to be able to configure your viewer to connect to a Dicom server and retrieve the appropriate Dicom images so that the ImageViewerComponent can (ultimately) render them. Retrieving the images from a Dicom server is also not the best approach as it is slow and likely requires you to store the image files on the local machine (there are ways around that, but it's the easiest way). Ideally, a web viewer would use a streaming server, which we will be developing soon, so that image retrieval is faster (and easier for the client to control) and everything is done in memory so that no files need to be stored on disk. A Dicom WADO server could also be used, although I don't know of any public implementations. If, however, you just want to render static bitmap images (no window/level tools, etc), you can still do it with the ImageViewerComponent. Instead of using DicomGrayscalePresentationImage and DicomColorPresentationImage, you could just use ColorPresentationImage and set its pixel data to that of your bitmap. In order to do that, though, you would need to store the jpeg images on your web server (and create them from the original dicom images somehow). I would like to caution you, that writing a web viewer is quite involved and although, in theory, you should be able to do it using the ImageViewerComponent, we can't guarantee it will work since we've never actually tried it out. Best of luck, Stewart |
|
| Real-time support available to Clinical Edition and Team Edition customers |
|
|
mre2mre
 Advanced Member Posts:34

 |
| 2008-02-14 11:22 AM |
|
thanks, first im glad to hear imageserver release, i'm developin web viewer for my customer when i finish web viewer project i'll share here. regards,
emre
|
|
|
|
|
lobatoasis
 New Member Posts:4
 |
| 2008-03-06 07:28 AM |
|
Thanks for all your replies I don't speak english very goog but i hope you understanding me. I have a problem with norman's code because i try it and not work. I have modified the code because the build failed. This is mi new code: LocalImageSop sop = new LocalImageSop("filename"); IPresentationImage img = PresentationImageFactory.Create(sop); PresentationImage image = (PresentationImage)img; int width = sop.Columns; int height = sop.Rows; Bitmap bmp = new Bitmap(width, height); Graphics g = Graphics.FromImage(bmp); IRenderingSurface surface = image.ImageRenderer.GetRenderingSurface(g.GetHdc(), width, height); surface.WindowID = IntPtr.Zero; DrawArgs drawArgs = new DrawArgs(surface, ClearCanvas.ImageViewer.Rendering.DrawMode.Render); image.OnDraw(drawArgs); drawArgs = new DrawArgs(surface, ClearCanvas.ImageViewer.Rendering.DrawMode.Refresh); image.OnDraw(drawArgs); image.OnDraw(drawArgs) throw a NullReferenceException and i don't know why. I think that image.ImageViewer has to be defined. What can i do? Thanks |
|
|
|
|
norman
 Senior Member Posts:811
 |
| 2008-03-06 09:05 AM |
|
Hi, You're absolutely right, a null image.ImageViewer is the problem. If you update the code from SVN, you'll notice that yesterday, we added IPresentationImage.DrawToBitmap, which encapsulates the code in my earlier post, hopefully without the exception. :) LocalImageSop sop = new LocalImageSop("filename"); IEnumerable< IPresentationImage > images = PresentationImageFactory.Create(sop); int width = 100; int height = 100; foreach (IPresentationImage image in images) { Bitmap bmp = image.DrawToBitmap(width, height); } Please let me know if that works, or if you get any other errors. Note that we're still stabilizing a few API additions, so don't be alarmed if you see some further API changes in the next few weeks. In particular, PresentationImageFactory.Create(imageSop) now returns IEnumerable, but that will be changed so that it accepts a Frame and returns just an IPresentationImage. Note also that ImageSop has been changed to include the concept of a Frame (all ImageSops now have at least one Frame), so as to support multiframe DICOM images. Norman |
|
|
|
|
lobatoasis
 New Member Posts:4
 |
| 2008-03-07 03:40 AM |
|
What i have to do to see your code from SVN? I haven't permissions to access to this sites https://trac.clearcanvas.ca/source/changeset/4794 https://trac.clearcanvas.ca/source/changeset/4803 |
|
|
|
|
norman
 Senior Member Posts:811
 |
| 2008-03-07 06:13 PM |
|
Hi, When prompted, just login with username=opensource, password=opensource. BTW, just so you know, the code I suggested above only works if you're writing a plugin for the viewer. If you try to simply use the ClearCanvas.ImageViewer.dll as a referenced assembly in say, a console app, it won't work as is since the CC.ImageViewer.dll assembly itself utilizes extensions/plugins. You actually have to do a bit of tweaking to get it to work properly. In the future, we're planning to modify the dll such that the plugin infrastructure isn't actually required and you can simply use it as a regular library if you want. N. |
|
|
|
|
lobatoasis
 New Member Posts:4
 |
| 2008-03-10 09:13 AM |
|
Dear norman, thank you very much for your help. I,ve can try your new code but i have to say that it gives me an error. IEnumerable< IPresentationImage > images = PresentationImageFactory.Create(sop); This line throw an exception: "Plugin directory could not be found." Why? I have all news dll's (i use dll's as a library) and i have referenced its in my project. |
|
|
|
|
norman
 Senior Member Posts:811
 |
| 2008-03-10 06:15 PM |
|
Hi,
Yes, that is exactly the problem I was referring to in my previous post. What's happening is that the ClearCanvas.ImageViewer.dll itself uses the plugin infrastructure, and so if you don't have that setup, it won't work. In a future version, we will be changing the code so that there is no plugin dependency and you will be able to use the dll as a simple library. Unfortunately, right now, getting it to work is a bit tricky, though it can be done. I've attached a sample project that shows you how. To be perfectly honest, I don't think it's a great solution, and if I were you, I'd wait until we make the appropriate changes.
Norman |
Attachment: DicomBitmap.zip
|
|
|
|
lobatoasis
 New Member Posts:4
 |
| 2008-03-13 04:32 AM |
|
Hi, You have reason Norman, it isn't a good solution. Have you try your code? I've tried and i can say that not work because the protected method AtLeastOne(object[] objs, Type extensionPointType) in Extension.cs throw a exception, do you know why? Is easy, objs always is null, so it throws the exception. I've tried to make some changes but is wasn't a good idea. Thank you very much Norman! Congratulations for your dedication! |
|
|
|
|
norman
 Senior Member Posts:811
 |
| 2008-03-13 08:53 AM |
|
Hi
I did try it and it does work, but I should have included some explicit instructions as to where certain files should be copied instead of simply leaving the files in their destination location. Sorry about that. Anyway, I've created a new project that I've attached that includes all the necessary post build steps, so you don't need to copy anything. Hopefully, you should be able to just change the path of the input and output files in program.cs, then build the project and run it. I've tried it and it should work. If something does go wrong, the following is the output directory structure that you're aiming for:
\common \ClearCanvas.Common.dll \ClearCanvas.Dicom.dll \ClearCanvas.Dicom.OffisWrapper.dll \ClearCanvas.log4net.dll \log4net.dll \nunit.framework.dll \logs \plugins \ClearCanvas.Desktop.dll \ClearCanavs.ImageViewer.dll \ClearCanvas.ImageViewer.Rendering.BilinearInterpolation.dll DicomBitmap.exe DicomBitmap.exe.config Logging.config
How the files are organized in the output directory is extremely important. It won't work if all the files aren't in the right place. (I'm sure you can see why I said in my previous post that this isn't a great solution. It's too complicated for something that should be very simple.)
Norman
|
Attachment: DicomBitmap.zip
|
|
|
|
jppena
 New Member Posts:1
 |
| 2008-03-13 12:51 PM |
|
Hi Norman I'm working in a project that includes a Dicom Viewer. I've been reading the solution for this topic for implementing my solution based in this way for opening images, I downloaded the sample, but the resulting image is entirely black.... I don't know why... can you help me...? Thanks a lot. Regards Juan Pablo |
|
|
|
|
norman
 Senior Member Posts:811
 |
| 2008-03-18 09:57 PM |
|
Hi Juan, Sorry for the delay. Anyway, just to be clear, you've downloaded the latest attachment I uploaded and built it, right? If so, can you post what's in the log file? Norman |
|
|
|
|
bigg
 Basic Member Posts:12
 |
| 2008-07-21 09:38 AM |
|
Hi, Has there been any more progress on an axtiveX web viewer? I am really looking forward to trying it out. |
|
|
|
|
norman
 Senior Member Posts:811
 |
| 2008-07-21 05:30 PM |
|
Hi, Sorry, but I'm afraid the web viewer won't be on our roadmap for a while, as we have a number of other priorities to take care of first. The earliest any work will be done on it will be in 2009 sometime. N. |
|
|
|
|
parmedevakil
 New Member Posts:4
 |
| 2008-08-22 11:08 AM |
|
Hi Norman, I downloaded your attachment and it works perfectly. But I cannot implement it in my own project file. I added the same references and everything. Except there is one problem. When I try to add reference, ClearCanvas.ImageViewer.Rendering.BilinearInterpolation.dll it says that it can't be added and that I should check to see it is valid COM assembly. When I build and run in my project it gives me a black blank output file. Please Advise. Regards, Parmede |
|
|
|
|
norman
 Senior Member Posts:811
 |
| 2008-08-22 11:12 AM |
|
Hi Parmede, That .dll is actually a C/C++ .dll, so you can't add it to your project. You just need to make sure that it's in your plugins folder, as ClearCanavs.ImageViewer.dll depends on it. N. |
|
|
|
|
parmedevakil
 New Member Posts:4
 |
| 2008-08-23 08:50 AM |
|
Hi Norman, Thank you for your fast response. But I still have problems. Just so you know my situation better, I have created a new project. In my project directory I have the same plugins and common folder as in your attachment. I also added the app.config file. I have added the 4 reference dlls: ClearCanvas.Dicom, ClearCanvas.Common, ClearCanvas.Desktop, ClearCanvas.ImageViewer. The project compiles smoothly. But it gets stuck at the Platform.StartApp(); line. It says "PluginException was unhandled. Plugin directory could not be found." If I comment out this line the program creates a blank bitmap output. Parmede |
|
|
|
|