Comparing 2 images using C# - c#

Can I compare 2 images and show the difference using C#?
How?

Sure you can. One (slow) way to do so would be to create a new empty image and then use GetPixel and SetPixel to construct the difference image.

Could be useful perform an image substraction (maybe better in GrayScale mode) as shown here:
How to subtract one bitmap from another in C#/.NET?

There is technology called SIFT( Scale Invariant Feature Transform ).This algorithm generates a feature file from an image in which it has salient points of that Image. This file is called SIFT feature.
You have to generate the SIFT feature file for the images that you want to compare. Then this technology has a matching function which you can use to compare the feature files. This function returns a number. the higher the number the more similar the images. in this way you find the most similar images from within a set.

Related

Comparing Two Faces (From another images) EmguOpenCV (C#)

I'm using EmguCV (It is .Net wrapper to the OpenCV image processing library).
I need to compare two images and check if this is the same person in both images.
Yes. But not directly in emgu, unless you want to make a lot of code.
Have a look at this page https://azure.microsoft.com/en-us/services/cognitive-services/face/
Here you supply two images and get score back.
It should be easy implementing the API

Image Matching using opencvsharp3

I'm novice in OpenCVSharp3 and I've been having a look at some examples for image matching using this library.
The key to my question is that I don't know what kind of modifications the code from this question needs to compare two images that are almost 100% identical, but one of them is rotated (unlimited rotation) and sometimes slightly displaced from the source (some pixels).
The method from such question basically compare if one image is inside the other, but my project only need to compare 5 images with the same size, where two of them are the same with slightly differences.
Is valid such algorithm?
EDIT:
Here is an example of 5 images to detect the same:
It can be valid but:
if you want unlimited rotation, you have to compare your reference image with an infinite combination of rotated other image.
if your other image is displaced from the source you will have to generate all the possible displacement images.
If you combine this two technique, you will have a lot of combination.
So yes, it can be done in generating all possible different images for one image, and compare them with your reference image.
It's not very robust, what will append if you try it on images displaced with a superior amount of pixels? if a color adjustment had be done on a image? if one is in gray-scale?
I recommend you to use machine learning for this problem.
I would proceed like this:
make a dataset of images
for each images, make a data augmentation (make all rotation, displacement, noise that it is possible).
Use a CNN and train it to recognize each variation of an image as the same image.
You're done, you have an algorithm who do the job :)
Here an implementation of tensorflow for C#
https://github.com/migueldeicaza/TensorFlowSharp
For a simple implementation of MNIST CNN with python see here
Here A video that explain how CNN works (look at the feature detection and pooling operation, it can help you)

capture and compare images

is there a way to grab a screen capture of a specific section of the screen and compare it to another image already store in disk. And if the image is identical, it would prompt something.
If you are trying to compare an image (or part of it) with another images, I searched internet and found that leadtools has correlation functions that compare an image with all the areas of the same dimensions in another image. For more information, see this link: http://www.leadtools.com/help/leadtools/v175/dh/po/leadtools.imageprocessing.core~leadtools.imageprocessing.core.correlationcommand.html
OR
This project may be what you're looking for:
https://github.com/cameronmcefee/Image-Diff-View-Modes/commit/8e95f70c9c47168305970e91021072673d7cdad8
Check http://www.developerfusion.com/code/4630/capture-a-screen-shot/ for examples on how to capture the screenshot.
The image comparison is a lot more complicated. The image that is stored on disk might have a different size, a different aspect ratio, or a different depth. Unless you can be sure that the screenshot and the image on the disk are absolutely identical, you'll have to look at a method that identifies similar images.
Take a look at the pHash Demo, which takes two images and outputs a similarity score. The algorithm it uses is pretty straightforward, and is available on the website.

C# Image comparison. Search one in the other

I have two images.
One is big and the other is small. I need an image comparison code/library which will search for the small one in the big one and give me the location and the percentage of the compared.
Suggestions?
Emgu is opencv (open computer vision) in .Net.
http://www.emgu.com/wiki/index.php/Main_Page
This will have more than enough functionality to do what you are asking for.
EDIT: I am assuming that C# is a key requirement.

Using C#, how do I search for images in a Windows file system like TinEye.com does on the web?

Hi and thanks for looking!
Update
For the sake of clarity, a third-party .NET library is just fine. Preferably an open-source or free one. The solution need not be native .NET.
Background
I am working on an enterprise web application for which the client has given us thousands of pages of content in MS Word documents that we have to parse, extract data, and send to the content database.
Within these docs are various embedded images representing a larger original image in a separate folder.
The client did not provide any paths to the original source image, so when we see content with an embedded image in the MS Word doc, we have to go through several "assets" folders and look for the corresponding image which is extraordinarily time consuming.
We are already using DocX to parse the documents, so you can assume that we have a list of bitmap images to loop through that we have pulled from the document.
Question
Given a list of bitmaps that we just extracted from the document, how do we search a different folder containing hundreds of images, for the matching image, and then return the file path to it?
TinEye.com does this over the web. I am wondering if, using System.Drawing or something, we can do it on a PC with C#.
Thanks!
Matt
Hate to propose an answer to my own question, but I think I might be on to something here. Here is heuristic/pseudo code for a C# forms app--your thoughts are appreciated:
Part 1
Using System.IO, traverse the "assets" folders and get all images.
For each image, Base64 encode it.
Take the resulting string and place in an XML file:
<Image>
<Path>C:\SomePath</Path>
<EncodedString>[Some Base64 String]<Encoded String>
</Image>
Now we have an XML file containing all original images, in Base64 form, along with their file path.
Part 2
Using DocX, extract all images from MS Word Doc.
For each image, use Linq-to-Xml to search for an exact match in the XML file from Part 1.
If there are no exact matches, start iterating the XML file and computing the Levenshtein distance.
While in the foreach store the XML node Id (or file path) and Levenshtein Distance as a key value pair in an object.
Take the k/v pair with the lowest LD score and return the file path.
For performance, set tolerance so that the foreach stops if a certain original image has an acceptably low LD score when compared to the image extracted from the document.
Since this is a one-off task, I don't need instant performance. So, I could run this tonight before leaving the office and, hopefully, come back tomorrow to a list of paths connecting the original images to the ones embedded in the docs.
UPDATE
The heuristic above worked beautifully! I ended up using the Sift library to efficiently calculate distances between Base64 strings. Specifically, I used their FastDistance() method. Having 100% accuracy on finding the images I need, even if the angle from which the photo was taken is slightly different.
There is no built-in algorithm in the .NET framework for generating image similarity. You'd need to use a third-party library or do it yourself. Lots of image similarity algo questions on SO:
Algorithm for finding similar images
How can I measure the similarity between two images?
comparing images programmatically - lib or class
One more, for .NET: Are there any OK image recognition libraries for .NET?. This one refers you to AForge, which seems to have the algorithm that you are after.
According to this SO answer to a similar question, you should look at OpenCV and VLFeat. The former has a C++ API and the latter a C API, so you would need to write your own P/Invoke wrapper or perhaps wrap them in a C++/CLI facade, which you could call from C#.

Categories