|
 | |  |
|
ClearCanvas Community Forums
|
Export DicomFile pixelData to JPEG or Image object
Last Post 2011-09-13 04:56 PM by cfdelaune. 77 Replies.
|
Sort:
|
|
Prev Next |
You are not authorized to post a reply. |
|
Julien.Jay
 New Member Posts:6
 |
| 2009-08-14 09:59 AM |
|
Well if forgot to mention it : I use the .NET Framework 3.5 and Visual Studio 2008. VS2005, .NET 1.1, 2.0 and 3.0 are also installed.
Actually I 'm using a proprietary framework and I have to write a plugin for it in order to handle DICOM files. That plugin uses the CC framework. And I test my plugin with NUnit, through the proprietary framework.
Then it may not be impossible that the .NET configuration is in a funny state as you say.
Given that, I guess it's pretty hard to know where exactly lies the problem. But anyway, It's not that important if a problem persist. As I've already said, I don't use the CC framework extensively. So it's not a big problem to comment out a line of code. thanks to opensource policy.
So don't waste too much time thinking on it ;) |
|
|
|
|
mikimilka
 New Member Posts:7
 |
| 2009-09-07 06:59 AM |
|
Hi Norman,
I've downloaded your attachment and started it, it gives me a black blank output file. I've tried changing files and output formats but its always same.
Any ideas?
edit: Im using binaries from 1.5 in Visual Studio 2005 |
|
|
|
|
mikimilka
 New Member Posts:7
 |
| 2009-09-08 05:28 AM |
|
update: I've managed to write similiar code in VB.NET and view images. I'm not sure why your code doesnt work properly on our machines. |
|
|
|
|
stewart
 Senior Member Posts:2033
 |
| 2009-09-13 11:40 PM |
|
Hi MM, I'm not sure which attachment you are referring to. Have you tried the steps I outlined a few posts back in this same thread for creating a new application that loads an x-ray image and then saves it as a bitmap? Best regards, Stewart |
|
| Real-time support available to Clinical Edition and Team Edition customers |
|
|
mikimilka
 New Member Posts:7
 |
| 2009-09-14 03:52 AM |
|
Hi stewart,
I was referring to Normans attachment project that was added a few posts back. The one that loads DICOM and saves it as PNG. I managed to make my own in VB.NET so its ok now. Thanks anyways. |
|
|
|
|
stiank81
 Advanced Member Posts:33
 |
| 2009-11-02 07:24 AM |
|
Posted By Jasper on 2009-07-27 10:05 AM
As a note for future reference: The code snippet at the very top of this thread works in versions 1.3 and earlier. In the coming release, the LocalImageSop class has been replaced with a basic ImageSop class for which you pass a LocalSopDataSource object. The resulting modified code for 1.5 and later is the following:
ImageSop sop = new ImageSop(new LocalSopDataSource("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);
I can't make the above code by Jasper work. I'm using the 1.5 version of the SDK. Here's what doesn't work:
* First there is the "PresentationImageFactory.Create". This doesn't take the sop argument, and I need to change the argument to sop.Frames[1]. Is this correct?
* image.Renderer property doesn't exist, and I can't find any substitute that looks similar.
* surface.ContextId --> surface.ContextID. ok..
* image.OnDraw function doesn't exist.
Am I missing something? What would be the correct approach for the latest 1.5 SDK..?
Cheers,
Stian |
|
|
|
|
stiank81
 Advanced Member Posts:33
 |
| 2009-11-03 03:00 AM |
|
So - I guess the answer is that most of these lines have been replaced by the DrawToBitmap? Yes? No? At least the following works fine: var file = new ClearCanvas.Dicom.DicomFile(dicomFilePath); var sop = new LocalSopDataSource(file); var img = new ImageSop(sop); IPresentationImage image = PresentationImageFactory.Create(img.Frames[1]); Bitmap bmp = image.DrawToBitmap(width, height);
|
|
|
|
|
stewart
 Senior Member Posts:2033
 |
| 2009-11-03 03:54 PM |
|
Hi, the code Jasper provided, although it doesn't compile as-is, was provided as a sample of how you *might* draw an image to an existing Bitmap, but there is now a DrawToBitmap(Bitmap bitmap) overload (in 2.0, yet to be released) that allows you to provide a Bitmap of your own rather than just width and height.
If you wanted to draw more efficiently, directly to a Control, rather than to a Bitmap first, then putting that Bitmap in a Control only to be rendered again by the Control, then you would use code like what Jasper posted. Have a look at TileControl.cs in the source code to see how IRenderer/IRenderingSurface can be used to draw directly to the Control.
Hope this helps,
Stewart |
|
| Real-time support available to Clinical Edition and Team Edition customers |
|
|
stiank81
 Advanced Member Posts:33
 |
| 2009-11-04 04:13 PM |
|
Thanks for the reply! Is there any timeframe on 2.0 release of the SDK? I see that there is an alpha out for Workstation, but couldn't see one for the SDK.. Stian |
|
|
|
|
stewart
 Senior Member Posts:2033
 |
| 2009-11-10 09:46 AM |
|
Hi, you can expect the 2.0 release of the workstation and SDK in the coming weeks. Can't be any more specific than that right now, unfortunately. We've only just started explicitly putting an Alpha on the website this release cycle and we typically put the SDK together at the end. We can consider putting an Alpha of the SDK out next time if there's significant interest. The SDK is just a complete copy of the released viewer with some Visual Studio templates and wizards. As a workaround, you can install the 1.5 SDK, but use a copy of the (installed) 2.0Alpha binaries and reference those from your plugins. Hope this helps, Stewart |
|
| Real-time support available to Clinical Edition and Team Edition customers |
|
|
alagarajaR
 Basic Member Posts:16
 |
| 2009-12-31 07:03 AM |
|
Hi Stewart,
I am trying to display a Thumbnail of DICOM image in my application. I need to read Bitmap from DICOM file and assign that to Picture Box. I tried using the codes posted in the forums. Its able to show images but not as the original dicom Image used to be. It seems that the Window Level and Window Width are not aligned properly. Tested the same with MRI Images it worked fine. Following is the code I used
LocalSopDataSource _dicomDataSource = new LocalSopDataSource("C:\\Temp\\2.dcm");
ImageSop imageSop = new ImageSop(_dicomDataSource);
IPresentationImage presentationImage = PresentationImageFactory.Create(imageSop.Frames[CurrentFrame]);
int width = imageSop.Frames[1].Columns;
int height = imageSop.Frames[1].Rows;
Bitmap bmp = presentationImage.DrawToBitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.Image = bmp
Am I missing anything? Have uploaded the screenshot in the following link.
http://www.flickr.com/photos/99957879@N00/4231122346/ |
|
|
|
|
stewart
 Senior Member Posts:2033
 |
| 2010-01-04 12:46 PM |
|
Hi, I had a look at your screenshot, but it's comparing ezDicom with the output of DrawToBitmap in CC. I'm very confident in the accuracy of the LUT and rendering code in CC, so are you certain that ezDicom is displaying it correctly? Could you try a couple of other viewers and see what they produce? Best regards, Stewart |
|
| Real-time support available to Clinical Edition and Team Edition customers |
|
|
stewart
 Senior Member Posts:2033
 |
| 2010-01-04 12:55 PM |
|
Actually, Jasper just reminded me that the "auto w/l" code is in a plugin called ImageViewer.Tools.Standard, and if you don't have that plugin, the LUT will be calculated based on the min/max pixel value. This should really be functionality that is included in the core viewer, so I've entered this ticket. For now, though, the workaround is to include Tools.Standard in your project, which will unfortunately drag along: Desktop, Desktop.Configuration, ImageViewer.Configuration.
Best regards,
Stewart |
|
| Real-time support available to Clinical Edition and Team Edition customers |
|
|
stewart
 Senior Member Posts:2033
 |
| 2010-01-04 12:56 PM |
|
And probably ImageViewer.Services, too. |
|
| Real-time support available to Clinical Edition and Team Edition customers |
|
|
alagarajaR
 Basic Member Posts:16
 |
| 2010-01-05 07:34 PM |
|
Thanks Stewart,
Will have a try and let u know. |
|
|
|
|
robertog
 New Member Posts:5
 |
| 2010-05-11 11:48 PM |
|
Good Night,
I'm adding your library lo display a dicom file on a pictureBox, I followed all the steps on a new project referencing the necessary dll's and works fine, but when I add it on the project I'm working, I get the next Exception:
2010-05-11 21:02:20,183 [1] ERROR - Exception thrown
Error loading plugin: ...\Debug\AxInterop.MODI.dll
System.FormatException: No se puede reconocer la cadena como valor DateTime válido.(It can not recognize the string as a valid DateTime value)
en System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
en System.DateTime.Parse(String s, IFormatProvider provider)
en System.Windows.Forms.AxHost.TypeLibraryTimeStampAttribute..ctor(String timestamp)
en System.Reflection.CustomAttribute._CreateCaObject(Void* pModule, Void* pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
en System.Reflection.CustomAttribute.CreateCaObject(Module module, RuntimeMethodHandle ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
en System.Reflection.CustomAttribute.GetCustomAttributes(Module decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes)
en System.Reflection.CustomAttribute.GetCustomAttributes(Assembly assembly, RuntimeType caType)
en System.Reflection.Assembly.GetCustomAttributes(Type attributeType, Boolean inherit)
en System.Attribute.GetCustomAttributes(Assembly element, Boolean inherit)
en System.Attribute.GetCustomAttributes(Assembly element)
en ClearCanvas.Common.PluginFinder.FindPlugin(String path)
2010-05-11 21:02:31,656 [1] ERROR - Exception thrown
System.FormatException: No se puede reconocer la cadena como valor DateTime válido.(It can not recognize the string as a valid DateTime value)
en System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
en System.DateTime.Parse(String s, IFormatProvider provider)
en System.Windows.Forms.AxHost.TypeLibraryTimeStampAttribute..ctor(String timestamp)
en System.Reflection.CustomAttribute._CreateCaObject(Void* pModule, Void* pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
en System.Reflection.CustomAttribute.CreateCaObject(Module module, RuntimeMethodHandle ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
en System.Reflection.CustomAttribute.GetCustomAttributes(Module decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes)
en System.Reflection.CustomAttribute.GetCustomAttributes(Assembly assembly, RuntimeType caType)
en System.Reflection.Assembly.GetCustomAttributes(Type attributeType, Boolean inherit)
en System.Attribute.GetCustomAttributes(Assembly element, Boolean inherit)
en System.Attribute.GetCustomAttributes(Assembly element)
en ClearCanvas.Common.PluginFinder.FindPlugin(String path)
en ClearCanvas.Common.PluginFinder.FindPlugin(String path)
en ClearCanvas.Common.Utilities.FileProcessor.<>c__DisplayClass1.
b__0(String filePath, Boolean& cancel)
en ClearCanvas.Common.Utilities.FileProcessor.ProcessDirectory(String path, String searchPattern, ProcessFileCancellable proc, Boolean recursive, Boolean& cancel)
en ClearCanvas.Common.Utilities.FileProcessor.Process(String path, String searchPattern, ProcessFileCancellable proc, Boolean recursive)
en ClearCanvas.Common.Utilities.FileProcessor.Process(String path, String searchPattern, ProcessFile proc, Boolean recursive)
en ClearCanvas.Common.PluginManager.FindPlugins(String path)
2010-05-11 21:02:31,902 [1] WARN - Exception thrown
ClearCanvas.Common.PluginException: No plugins could be found.
en ClearCanvas.Common.PluginManager.FindPlugins(String path)
en ClearCanvas.Common.PluginManager.LoadPlugins()
en ClearCanvas.Common.PluginManager.EnsurePluginsLoaded()
en ClearCanvas.Common.PluginManager.get_Extensions()
en ClearCanvas.Common.DefaultExtensionFactory.BuildExtensionMapOnce()
en ClearCanvas.Common.DefaultExtensionFactory.ListExtensionsHelper(ExtensionPoint extensionPoint, ExtensionFilter filter)
en ClearCanvas.Common.DefaultExtensionFactory.CreateExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter, Boolean justOne)
en ClearCanvas.Common.ExtensionPoint.CreateExtensionsHelper(ExtensionFilter filter, Boolean justOne)
en ClearCanvas.Common.ExtensionPoint.CreateExtension()
en ClearCanvas.ImageViewer.BasicPresentationImage.get_ImageRenderer()
2010-05-12 10:10:32,987 [1] ERROR - Exception thrown
An error occurred while attempting to register the dicom codec extensions.
ClearCanvas.Common.PluginException: No plugins could be found.
en ClearCanvas.Common.PluginManager.FindPlugins(String path)
en ClearCanvas.Common.PluginManager.LoadPlugins()
en ClearCanvas.Common.PluginManager.EnsurePluginsLoaded()
en ClearCanvas.Common.PluginManager.get_Extensions()
en ClearCanvas.Common.DefaultExtensionFactory.BuildExtensionMapOnce()
en ClearCanvas.Common.DefaultExtensionFactory.ListExtensionsHelper(ExtensionPoint extensionPoint, ExtensionFilter filter)
en ClearCanvas.Common.DefaultExtensionFactory.CreateExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter, Boolean justOne)
en ClearCanvas.Common.ExtensionPoint.CreateExtensionsHelper(ExtensionFilter filter, Boolean justOne)
en ClearCanvas.Common.ExtensionPoint.CreateExtensions()
en ClearCanvas.Dicom.Codec.DicomCodecRegistry..cctor()
2010-05-12 10:10:33,001 [1] ERROR - Exception thrown
ClearCanvas.Dicom.Codec.DicomCodecException: Unsupported transfer syntax
en ClearCanvas.ImageViewer.StudyManagement.DicomMessageSopDataSource.DicomMessageSopFrameData.CreateNormalizedPixelData()
en ClearCanvas.ImageViewer.StudyManagement.StandardSopDataSource.StandardSopFrameData.GetNormalizedPixelData()
en ClearCanvas.ImageViewer.StudyManagement.Frame.GetNormalizedPixelData()
en ClearCanvas.ImageViewer.Imaging.PixelData.GetPixelData()
en ClearCanvas.ImageViewer.Imaging.PixelData.get_Raw()
en ClearCanvas.ImageViewer.Rendering.ImageRenderer.Render(ImageGraphic imageGraphic, IntPtr pDstPixelData, Int32 dstWidth, Int32 dstBytesPerPixel, Rectangle clientRectangle)
en ClearCanvas.ImageViewer.Rendering.GdiRenderer.DrawImageGraphic(ImageGraphic imageGraphic)
en ClearCanvas.ImageViewer.Rendering.RendererBase.DrawSceneGraph(CompositeGraphic sceneGraph)
en ClearCanvas.ImageViewer.Rendering.RendererBase.DrawSceneGraph(CompositeGraphic sceneGraph)
en ClearCanvas.ImageViewer.Rendering.RendererBase.Render()
en ClearCanvas.ImageViewer.Rendering.GdiRenderer.Render()
en ClearCanvas.ImageViewer.Rendering.RendererBase.Draw(DrawArgs drawArgs)
Thanks for your response
Roberto Garcia
|
|
|
|
|
steve
 Senior Member Posts:1885
 |
| 2010-05-13 10:27 AM |
|
Roberto, Its a bit hard to say what's going on, but there's a few clues from the log: - The first couple of log lines are related to the library scanning the assemblies (via reflection) you have setup to see if any of them are ClearCanvas plugins. There appears to be some issues with some of these assemblies with a DateTime attribute. This appears to be a non-fatal error. - the last log is related to the file you're trying to display appears to be compressed, but you don't have any codecs that were found as plugins. - We have an RLE and Jpeg plugin available that you could use for this. Compiled versions of the plugins are in our ReferencedAssemblies directory in our repository. You can also build these from the ClearCanvas.Dicom.sln file in our repository (in the DICOM folder). Steve |
|
| Real-time support available to Clinical Edition and Team Edition customers |
|
|
robertog
 New Member Posts:5
 |
| 2010-05-13 10:34 AM |
|
Hi Steve I look on Common solution and restrict the search of codecs to only ClearCanvar*.dll, and the project loads the codecs correctly. Thanks for your help. Roberto Garcia |
|
|
|
|
rajeshiyer
 New Member Posts:4
 |
| 2010-07-30 02:22 AM |
|
Sir,
My Name is rajesh iyer. i am trying to customize a project in which i have to show dcm images in asp.net web application.
sir, please let me know how to do it, i am really looking forward your reply!
Regards
Rajesh Iyer
Email Id: rajesh.chelakar@roarsinc.com
|
|
|
|
|
kdupasquier
 New Member Posts:9
 |
| 2010-08-26 03:07 PM |
|
Hello, thanks to all the previous commentors, this thread helped out a lot. I have implemented the below code snippet in a REST service and it is executing properly and returning a bmp on my 64bit Dev machine when hosted by a Console Client, however when it is installed as an IIS hosted service there is an execption thrown in the DrawToBitmap function call. The error is tracked down as HRESULT: 0x8007000B, which leads me to believe there is a mismatch between the BilinearInterpoliation.dll that is referenced in, since IIS is a 32bit hosted. I have attempted to build this as win32, but that has not fixed the issue. I have also tried building the ImageViewer.dll and ImageViewer.Tools.Standard.dll as win32 without success. Any guidance would be greatly appreciated! The source code was pulled down from Revision14114 on 8/24/2010 Thank you! - Kelly LocalSopDataSource dicomDataSource = new LocalSopDataSource(filepath); ImageSop imageSop = new ImageSop(dicomDataSource); IPresentationImage presentationImage = PresentationImageFactory.Create(imageSop.Frames[frameNumber]); Bitmap bmp = presentationImage.DrawToBitmap(128, 128); //ERROR is thrown here: An exception was thrown in the rendering pipeline. //get the file stream to pass back MemoryStream memoryStream = new MemoryStream(); EncoderParameters encoderParameters = new EncoderParameters(1); encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L); bmp.Save(memoryStream, GetEncoder(ImageFormat.Png), encoderParameters); memoryStream.Position = 0; return memoryStream; |
|
|
|
|
| You are not authorized to post a reply. |
|
Active Forums 4.1
|
|
|
|
|
 | |  |
|