Click here to Skip to main content
12,691,523 members (31,485 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# Javascript API
Let me first clarify my requirements :- I am making an application which will take any image and identify it (e.g. if I upload a picture of an apple then it should return me the text "apple"). I will use this text to search some products (this search functionality is already done).

I have seen Google Image search in which if you upload an image Google returns related images with a corresponding text (which identifies the image) in the search box.

I have searched for Image APIs - Google & Yahoo APIs are Depreciated :( Bing supports text to image search (Please correct me if I am wrong) TinEye api has Image to Image search but no corresponding text (Please correct me if I am missing something)

Thanks in Advance
Posted 11-Jun-12 7:40am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Based on your question, "you upload any image and identify it".
1) For this, first you have to store (or save) many sample images (like apple, melon....) with proper texts (name of the object on the image for example) in your app.
2) Store the images in a defined size (256 x 256, or 512 x 512). This makes it easy and consistant.
3) Upload your image (target image) with the the same size described above (256 x 256 or 512 x 512).We are keeping consistancy.
4) If your image to be uploaded is larger than the defined size above, resample it and make it the same size as the sample images in your system.
5) Keep both sample and target images in the same image format (e. g., Format24bppRgb). This is a format consistancy.
6) Make image CORRELATION and calculate the correlation coefficinets between the Sample Images (again this is not image but images, because you have many sample images in your system) and the target image. Now, you got many correlation coefficients, select the highest one and corresponding image and text. Then, show up the text or do your search with your completed search functionlity.
You may use third party for image correlation job. This may help you:[^]
ip28 11-Jun-12 14:35pm
@muhtarqong - Thanks a lot for your answer. I will make my understanding clear as per my requirement. I have a database with images of same format and size, and yes it will be feasible to convert the images to the very same format and resolution. But can you please explain me little bit more about the correlation stuff ?
muhtarqong 11-Jun-12 15:23pm
OK, first the correlation, for easy understanding without math fomular, is:

find out the similarity between two series of numbers,

1) NumberSeries-1: 111, 121, 144, 147, 255, 249, 240, ..., 0 (e. g., image-1)

2) NumberSeries-2: 111, 121, 144, 147, 255, 249, 240, ..., 0 (e. g., image-2)

The correlation coefficient between these two number series is 1.0. In other words, they are complete the same thing.

Please see the following:

1) NumberSeries-1: 110, 121, 142, 147, 255, 249, 240, ..., 1 (e. g., image-1)

2) NumberSeries-2: 111, 121, 144, 147, 254, 249, 241, ..., 0 (e. g., image-2)

These tow number of series has high correlation coefficeint (I did not calculated it, I am sure the correlation ceof is very high between them).

As we know the images are array of the numbers like the above. So, we can calculate the similarity between them.

Note that if you have images in the database and if they are in RGB format (has three channels),convert them to Graysacle (one channel) before doing correlation. Thus, the correlation process become very fast.

ip28 11-Jun-12 15:56pm
@muhtarqong hey thanks a ton.. I knew correlation in mathematics lil bit but now I am clear. So to be precise I will have to convert both images into grayscale and calculate the correlation coeff if the corealtion coeff is high it means the images are similar. I will try this tomorrow and let you know.
muhtarqong 11-Jun-12 16:20pm
ip28 12-Jun-12 3:23am
Hi Muhtarqong, I have tried to convert the images into grayscale by the following method (saw it in stackoverflow)
public static Bitmap ConvertToGrayScale(Bitmap image)
int x, y;
Bitmap result = null;
// Loop through the images pixels to reset color.
for (x = 0; x < image.Width; x++)
for (y = 0; y < image.Height; y++)
Color pixelColor = image.GetPixel(x, y);
Color newColor = Color.FromArgb(pixelColor.R, 0, 0);
image.SetPixel(x, y, newColor); // Now greyscale

result = image;

return result;
But for 2 images( & of same dimensions (I have tried with 250X250 px) I am getting different sizes of byte arrays the Apple logo (2nd image) is larger. In this case how do I make sure that the correlation coefficient is correct ? (The correlation coeff can only be calculated for arrays of same size)
ip28 12-Jun-12 10:53am
Sorry for the previous question .. I got the solution.. while I was converting the grayscale image into byte array the imageformat was incorrect. It should be BMP
ip28 12-Jun-12 10:54am
I will test the application tomorrow and let you know the final result.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170117.1 | Last Updated 11 Jun 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100