WPF - Specialized image display for 16 bit depth grayscale monitors - c#

I am currently developing an application to display 16 bit grayscale images to a 16 bit grayscale compatible monitor.
Most of my experience in software development has been in WPF. However I am reading that even though WPF can accept Gray16 type images, they are internally converted to 32 bit color.
In pursuit of this, I have been using the WPFDXInterop https://github.com/microsoft/WPFDXInterop/ to try and output the image as I want though a DirectX 11 based custom control, and use CUDA and OpenCV at times for image processing.
Am I out of luck in using WPF for this situation? Do I need to change coding environments?
It has been important to me to be able to continue using CUDA and OpenCV for the image processing, but I can change from DirectX to OpenGL is I have to, and learn something other than WPF.

Related

Measuring SMALL blobs in bitmap, using OpenCV

I am in need to SIZE small white blobs on a black background, using OpenCV over C#.
Right now, I am starting to use the OpenCvSharp library, but, given that I am early in the development (started two days ago) I wonder if it's the best library for C#, or if you guys would use something else.
The task is to find small pinholes (In the 10/20 micron range, up to 100 micron) in an aluminum foil sample, which is placed in a machine that returns a 1800x1800 pixel picture with the pinholes on a black background.
My problem is simple, but the solution, I think, isn't: How do I "size" the pinhole, using OpenCV?
I know that the size is a clear indicator... But the smallest pinholes 10/15 micron are very difficult to recognize, because they are pretty similar in size (in the image), but vary in brightness.
Any of you guys find this challenge even remotely interesting?

Camera RAW image processing with Windows Store app

I want to create a Windows Store app in C# to process to camera RAW images. It looks like I can load the RAW images using Microsoft's Windows Imaging Component (WIC), but when then I want to manipulate the images in a Windows Store app, I run into a problem.
To manipulate images in Windows Store apps, the primary option I found is using a WriteableBitmap object, but WriteableBitmap objects have only 8 bits per channel. Most DSLRs, including mine, have 14 bits per channel. I don't want to lose that much color depth. I suppose I could go the DirectX approach, but I'd rather not have to deal with C++ for this project. There's SharpDX, which lacks a bit in documentation, but I'd tackle it anyway if it's the best choice. Are there other ideas?
So what are the options, and which solution would you favor in my position? How can I load RAW images into a Windows Store application and make changes to those images without losing color depth?

Native WPF vs. Custom DirectX for displaying large images

I need to speed up my image viewer, and wondering if I should be looking into creating my own DirectX control to do so.
My image viewer displays medical images. They can be pretty large. We're talking 55mb when it comes to mammography. The pixel data is 16bit greyscale stored in a ushort array. Without getting into the gory details, my current approach is loading the pixel data into an ImageSource, and using the WPF Image control.
I've never done anything with DirectX. Is it worth diving into it? Would it be any faster than the native WPF stuff? If so how significantly? Or, should I just forget about DirectX and look into areas where I can improve my current approach?
Before somebody says so, I know WPF utilize DirectX. I'm wondering If removing the WPF layer and writing the DirectX myself will improve performance.
I have some experience drawing multi-gigabyte satellite and chart imagery. Working with imagery around 55MB should probably work okay even without trying to optimize it too much. You haven't really given enough detail to recommend one alternative over the other, so I will give my opinion on the pros and cons.
Using 2D windows APIs will be the simplest to implement and should always be fast enough if you don't need to rotate and simply want to display an image and zoom and pan around. If you treat it as one large image the performance will not be as good when you zoom out if you are drawing with halftoning to give a nice smooth image. This is because it will effectively have to read all 55mb of image every time it draws.
To get around this performance issue you can make multiple bitmaps, effectively mip-mapping your image. As you zoom out you can pick the reduced resolution image closest to the resolution you are trying to draw . If you are not familiar with mip-mapping here is a Wikipedia link:
http://en.wikipedia.org/wiki/Mipmap
Implementing it with DirectX will be 10x as difficult. Different graphics hardware has different maximum texture sizes. Most likely you will need to break your image up in to multiple textures to draw and you will also have to keep track of render states, viewing matrices, etc.
However, if you do use DirectX, you can implement lots of real-time photo adjustments You can do real-time rotation by simply adjusting view matrices. You can do real-time contrast, brightness, gamma, and sharpness easily in a pixel shader.
There are two other API's I might suggest. If you are willing to limit yourself to Vista or later then Direct2D would be a little simpler than Direct3D. Also if you ever will need to implement it on a non-windows platform I would suggest using OpenGL instead. My current project is in Direct3D because a few years ago when we started it OpenGL was falling behind and I didn't forsee the popularity of Android devices. I now wish we had used OpenGL instead.
Try profiling to see where WPF is spending its time. Are you displaying the images at their native resolution? If not it might be worthwhile to do some preprocessing and create 1/2 resolution versions.

Image API/App which can perform image manipulation on the fly?

Do any of you know an API or application which can handle real time image manipulation?
Basically if I provided an image, this app would output perhaps a silhouetted version, or perform some other form of image manipulation, like roshak type blotting?
If you don't know of an application like this, do you know if this is possible using WPF?
I know some of you might respond with "hire someone" to do it. I basically want to determine how much work is involved prior to that. I'm an ASP.NET dev with no experience with WPF but if it's something that isn't extremely involved, I'd love to take a shot at it and get my WPF feet wet.
Thanks guys.
Pixel shaders, pixel shaders, pixel shaders.
WPF has built-in support for these since .NET 3.5, and from what I've seen it's not too tough to set them up. Not to mention there are tons of examples out there already.
You could look into GDI+ for any image transformation/filtering needs There are a number of tutorials out there, this series can get you going (5 parts):
Image Processing for Dummies with C# and GDI+ Part 1 - Per Pixel Filters
Image Processing for Dummies with C# and GDI+ Part 2 - Convolution Filters
Image Processing for Dummies with C# and GDI+ Part 3 - Edge Detection Filters
Image Processing for Dummies with C# and GDI+ Part 4 - Bilinear Filters and Resizing
Image Processing for Dummies with C# and GDI+ Part 5 - Displacement filters, including swirl
EDIT: WPF has quite a few Pixel Shaders, per Charlie's response below, that look good, wasn't aware of those as I haven't taken the WPF plunge yet.

16 bit grayscale image display in WPF

I am developing an application that displays 16 bit grayscale images. The UI for the application was originally created using Win Forms and since Win Forms does not support 16 bit grayscale I wrote a custom openGL control to display the image. Within the last few months we have convert the UI to WPF, but continued to use the openGL image display via a WindowsFormsHost.
WPF is DirectX based so it would make sense to try and get away from the openGL, but does WPF natively support 16 bit grayscale images? or will I have to create a DirectX control?
Also, the openGL control isn't only used to display the image data. The contol allows the user to manipulate the image in various ways (Flip, rotate, Zoom, pan, crop, etc); as well as annotate the image (draw lines, rectangles, measurement angles, etc). If I'm simply using WPF to display the image, how can I also manipulate and annotate using WPF? Plus, I am using a shader to do some color mapping on the image texture. Is something like this possible with WPF or will I have to color map the image data manually before displaying?
I have never used DirectX, so if writing a DirectX control is necessary how difficult will it be to learn and implement what I need?
As for the shaders parts, WPF have access to the HW shaders (and it can emulated them in SW if needed) they are called bitmap effects.
Greg Schechter's covered how to write a custom effect in his blog

Categories

Resources