How to handle large Images? - c#

I want to create my own Google Map like this:
My problem is that I can't load and edit my large images.
My Images:
PNG / JPG
700 MiB
300000px x 300000px
My attempts:
ImageMagick
.NET C# / BitmapImages ...
C++ / OpenCV
general image classes in Java and Python
With which language / library I can edit these big images.

I help maintain libvips, an image processing library designed to work with very large images. It's free and works on Linux, Mac and Windows. You can use it from the command-line, C#, C/C++, Python, Ruby and others.
You can make your google maps tiles from the command-line like this:
vips dzsave hugefile.tif myoutputdir --layout google
Or from Python (for example) like this:
import pyvips
image = pyvips.Image.new_from_file("somehugefile.tif", access="sequential")
image.dzsave("filename/of/pyramid", layout="google")
And it'll scan your huge tiff image and generate all the tiles. It's fast, it needs little memory and it'll work on images of any size. I regularly make 200,000 x 200,000 deepzoom images from microscope slides using my small laptop.
There's a chapter in the libvips docs introducing dzsave and explaining how to use it.

This is not a full answer, but I need a little more space than a comment can give.
Take a look at the large image support section on the ImageMagick or the discussion board.
This answer mentions the VIPS package which might be helpful.
You might also consider posting in photography stackexchange, or even blender stackexchange - for example I saw this answer which mentions writing individual image tiles - also here, although that question is about rendering. Blender is not specifically for image processing and editing, but it's pretty amazing and flexible and has a very active and supportive community. You can use python within Blender as well.
You could also think of asking in gis stackexchange.
When you post in the other stackexchanges, take a look around first and make sure you write your question so that it does not look too off-topic for that site.
Good luck - it seems tiling is everywhere!

Related

Search a specific folder for an image that is found within a picture

Been trying Google for a while and haven't even found a start point for this problem.
I am looking for a starting point for developing a check in system. I have a large database of images of inventory in house. Very clean digital HD images with no background or anything. I am looking to do a local image search.
I will have a small temp folder with only the images of products in the current order. Then to verify that the item in employees hand is that same, I want to scan the item in real time and compare it to the images in the folder. and work from there.
I can't seem to find any documentation on any classes that can help me with this functionality.
For example say I have an image on my PC, and I print out that image to paper in a VERY high quality. I want to then be able to match the print out to the original file.
Is there anything built into .Net for this?
I have done something similar in the past. But in my case it was a facial recognition system. It worked pretty well but you have to remember that it might not work in 100% of the cases. Visual recognition is a very complicated subject and we have yet to develop a way to have a flexible 100% accuracy system.
As to how I did it, I developped a NN(Neural Network) algorithm. This algorithm had to be trained against a specific set of pictures.
Another popular approach is to use a SVM(Support Vector Machine) algorithm instead of a neural network. Then again, you will most likely not get a result that is 100% accurate.
Keep in mind that there are many different algorithms that can be used to do visual recognition. Two other popular algorithms for facial recognition are Eigenfaces and Fisherfaces.
Sadly, I have not worked with those kind of project in .Net. But you might want to check for a third party NN or SVM library for .Net.
Here is a link to a SO thread about NN
Open-source .NET neural network library?
Here is a link to a SO thread about SVM
Support Vector Machine library for C#

Processing images without GDI+ in C#

For some reasons, I need to write few image processing functions without using GDI+. I need to be able to do the following operations on images.
Draw some shapes on existing images (mostly rectangle with a plain background color). Regularly i do this using Graphics.DrawImage() function in GDI+.
Draw texts on existing image. Regularly I do this using Graphics.DrawString() function in GDI+
Save image to MemoryStream. Regularly I do this by Image.Save(stream, imgformat) function in GDI+
Get image bytes. Regularly I do this by MemoryStream.ToArray() function. I need bytes because I need to be able to send image to HttpContext() using the context.Response.BinaryWrite(imageBytes) method.
I've already looked at AForge.net, but it is missing Image.Save() method. It uses native Bitmap.Save() method of GDI+. So I seem to have no way of surviving GDI+ with AForge.
I've also looked at OpenCV and its .NET wrapper Emgu, but after 2 days of hard try, I was not able to successfully integrate the project into my own project (I know this sound silly, but that is truth. Following all the tutorials, probably 20+ SO posts on this did not help, because my solution structure is a little bit more than (more complex) a regular solutions).
How can I achieve this? Show me some way please. Have you even found yourself in such a situation (situation where you need to process images, but no GDI+)? What are the other libraries that could help me?
There's a recent project that's gathering momentum called, appropriately, "ImageProcessor": https://github.com/JimBobSquarePants/ImageProcessor - NuGet reports over 344,000 downloads as of June 2016.
Scott Hanselmann did a feature on it about 8 months ago, explaining the motivation given that .NET Core does not have System.Drawing (and I note that Windows Azure does not officially support GDI in Website Roles): http://www.hanselman.com/blog/RFCServersideImageAndGraphicsProcessingWithNETCoreAndASPNET5.aspx
I just attempted to answer a similar question here:
server-side graphics generation in .net/c#
Adding any other vector graphics (and layout) would be quite simple as well. Let me know if you would like a sample project or code.

C# image recognition

I'm currently searching for a C# image recognition library.
What I want to do:
I want to write a function that scans an image and returns if another image is part of it. Or at least something that looks familiar in case that the angles of the two objects are different.
The link to a possible library and a short code example would be great!
Thank you in advance!
Since you didn't mention that you are only looking for free libraries, here are some paid ones:
MVTech HALCON
Cognex VisionPro
Both have demo versions and quite good .Net wrappers bundled to the SDK, and I think both have the functionality you need. In Halcon, you might want to try different matching algorightms (gray value based, descriptor based, etc.), while in VisionPro PatMax or PatQuick might suit your needs. But obviously you have to try which one is the best for your specific problem.
EmguCV (http://www.emgu.com/wiki/index.php/Main_Page) is a good .NET OpenCV wrapper. It has a bunch of sample projects bundled. Run samples and you will get the idea of what can be done and how.
The Accord.NET library is not actually an image recognition tool set, however it provides the base for what you are aiming for. It contains many Imaging classes required for building an image recognition system. Accord.NET is LGPL licensed, except for some parts of it (e.g. its FFmpeg wrapper project).

Image straightening algorithm

I am looking for a way to auto-straighten my images, and I was wondering if anyone has come across any algorithms to do this. I realize that the ability to do this depends on the content of the image, but any known algorithms would be a start.
I am looking to eventually implement this in C# or PHP, however, I am mainly after the algorithm right now.
Is this possible with OpenCV? ImageMagick? Others?
Many thanks,
Brett
Here is my idea:
edge detection (Sobel, Prewitt, Canny, ...)
hough transformation (horizontal lines +/- 10 degrees)
straighten the image according to the longest/strongest line
This is obviously not going to work in any type of image. This is just meant to fuel the discussion.
Most OCR programs straighten the scanned image prior to running recognition. You probably find good code in the many open source'd OCR programs, such Tesseract
Of course this does depend on what type of images you want to straighten, but there seems to be some resources available for automatic straightening of text scans.
One post I found mentioned 3 programs that could do auto-straightening:
TechSoft's PixEdit 7.0.11
Mystik Media's AutoImager 3.03
Spicer's Imagenation 7.50
If manual straightening is acceptable, there are many tutorials out there for how to straighten them manually using Photoshop; just google "image straightening"
ImageMagick has the -deskew option. This will simply rotate the image to be straight.
Most commercial OCR engines like ABBYY FineReader and Nuance OmniPage do this automatically.
The Leptonica research library has a command line tool called skewtest which will rotate the image.
I have not found a library which can take an image which has been distorted in any other way (like pin cushion or if it has been moved during a scanning operation, or removing the warp at the edge of a book). I am looking for a library or tool that can do this, but cannot find one.
Patrick.

TIFF image prints fuzzy (but works fine from Paint.Net)

I have created a TIFF image from several lines of text, and it's quite large at 300DPI. The image itself looks pretty good. The font is set as followings when drawing the string to the image:
drawing.SmoothingMode = SmoothingMode.Default;
drawing.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
When I print the image, the text comes out fuzzy (I'm printing to a low-rez printer). But, if I take the exact same image and print it from Paint.NET, it prints beautifully. The difference is that when I hit Print in Paint.NET, it asks me if it should sharpen the image for printing -- when I say yes, that's when it works.
My question is what the heck is Paint.NET doing to sharpen the image and how do I mimic that? I will post some code later tonight to assist with an answer, if anyone has an answer.
Thanks!!
There is a .NET C# library called AForge.NET. It has many components and one of these components is an imaging library that does, indeed, have a sharpen filter (among many other types of filter). You can download the library here: http://code.google.com/p/aforge/
And if you need help on how to use it, look here: http://www.codeproject.com/KB/GDI-plus/Image_Processing_Lab.aspx

Categories