Can't find part of image in original - c#

I'm trying to implement a function that will scan the computer screen for a given image of an icon and get its coordinates.
Since the image of the icon will be taken by me I thought it would be best not to use any image recognition technique but rather byte comparison, thinking if I take a screenshot of the screen, while the icon is visible, I will cut just the icon, save it as *.bmp and then instruct the program to take a Bitmap screenshot, convert it and the icon image to a byte array and look for one in the other and, perhaps, by the location of the bytes of the icon image in the screenshot determine where on the screen it is.
I fail at step 1, which is - use the "Prt Scr" button to take a screenshot, save it as *.bmp then copy the part with the icon (in this case The Start Button), save only that as *.bmp separately and then use the ImageConverter class to convert them both into byte arrays and look for one in the other.
Initially I've tried most all the answers from this question but they all failed to find it. Then I got a StringBuilder and iterated through each array, appending each element to the StringBuilder with a comma after it. Then I copied both results to Notepad++ and searched for the Start Button bytes in the full screenshot. They aren't there.
So I wonder why the bytes wouldn't be there, considering one is a direct copy of a smaller section of the bigger picture and, two - is my approach to find the coordinates of a smaller image inside a larger one by using byte comparison wrong?
EDIT: Removed code as it doesn't matter in this case.

Related

Save a list of elements inside an image in c#

Is there anyway to save a list of elements/linked list inside an
image?
I need to save information like a relationship between neighborhood pixel values in an image. So i will be using a List<> containing (pixel value, relative coordinate of next pixel)
List<Dictionary<int, int[]>> globalList = new List<Dictionary<int, int[]>>();
// list contains a map for [water mark pixel, {matching cover image pixel, best match value}] for each watermark
Please suggest some ways to save it inside my image as a secret information which is hard to remove except methods like :
Increasing bit-depth
save into image properties as header info
I know these can be removed easily. I need a non-removable way ( in C#).
Your question was kind of unclear, but I assume you're trying to add a hidden watermark?
The easiest way would probably be to convert your data to a BitArray and then increase the value of each pixel's color by 1 or 0 bits as you iterate through the array. You would then retrieve your data by comparing the resulting photo to your original.
Edit:
If you want to store the data outside of the header/properties and without modifying colors, then I don't have a solution for you. As far as I know, those are your only options. You could always do what I mentioned and then include the watermarked portion of your image as a static BitArray within your application for comparison.

Retrieve original image from thumbnail

I have made a thumbnail of an image using Image.GetThumbnailImage Method.
Now I want to get the original image and display that original image to a different pictureBox when I click on the thumbnail (which is a different pictureBox).
Does anyone know how can we do that? I have search on the Internet and all I found is create a thumbnail, I didn't find any method to retrieve back the original image
If you want to have thumbnails which lead to an original version of the image, you need to at least keep and store the original version of the image.
When the user clicks the thumbnail, display the original version of the image that you stored.
You cannot restore original images from a thumbnail
Given a thumbnail of an image, you can't expand it back into the original image. Scaling it down into a thumbnail is a destructive process which removes the vital information.
Consider... given this thumbnail:
How could you recreate this image?
Most of the information in the larger image is missing in the thumbnail. The cracks in the paint aren't there in the thumbnail. Nor can you spot her veil, make out the background, see the white flecks on the canvas, or notice the waviness of her hair. You can't see the ripples of her dress nor the folds and creases in the fabric. In the thumbnail, all those things no longer exist: the scale down has destroyed all that information.
Trying to reconstruct the larger image from the smaller would be like akin to recreate a 20-page novel from a half-page summary of its major points: you can guess at how the author might have written it, but you'll never know word-for-word what it was originally.
The image of the Mona Lisa was from Wikipedia.

C# Changing the cursor's clicking/pointing position?

So the default cursor is the "Arrow" cursor and the top-left of the arrow (where the point is) is the part that clicks or interacts with other controls. How can I change the pointing part to say the tail of the arrow?
What I have is a custom cursor (a bitmap image) which is a circle at 16x16 size and I want the very center of it to be the pointer. I have another custom arrow-like cursor that points downward-left also 16x16 and I want the bottom-left corner of the cursor to be the pointer. I think there's a property in the cursor class for this but I'm not sure what it's called.
This is actually specified in the CUR file format.
The CUR file format is an almost identical image file format for
non-animated cursors in Microsoft Windows. The only differences
between these two file formats are the bytes used to identify them and
the addition of a hotspot in the CUR format header; the hotspot is
defined as the pixel offset (in x,y coordinates) from the top-left
corner of the cursor image where the user is actually pointing the
mouse.
Programs that can edit CUR files generally allow you to specify the hot spot. More information can be found in this question.
What you want can't be done through code. I wanted do the same thing but it's not possible.
In fact, the Cursor class has a property called HotSpot, which is the point that you want change. However this property is readonly.
The only way to change this is at file loading (on a .cur file, I suggest you using Paint .net with Cursor and icons plugin (search over the web) to edit cursor). An important thing: the cursor must be a file and not a resource or things like that (must be a file on the file system) to load it. Remember it, I had bad times testing in other ways.
The idea that I have in mind is: edit cursor file just when you need to change the hotspot, however this require for you writing an api that allows you to change the hotspot on a cursor file. I obviusly don't know how this file is built so you must continue from here.
Hope this was useful

Bitmaps in WPF - give watermarking effect and then recover images individually

I am working on a project where I need to play with two bitmaps. I am putting them in a grid one over the other with reduced opacity (to give a watermark effect).
I am rendering the grid to a bitmap using RenderTargetBitmap and saving the bitmap to a file.
Now my requirement is to load the rendered bitmap again and recover the original pictures separately. Is there any way to recover the original images again. I am not able to think any algorithm to implement this.
My aim is to give a watermarking effect and then recover the images individually.
No. The information is lost during "flattening" of the image.
You need to save both images and information about their properties (position, opacity) into single file. And restore it on load.
If your goal is to simulate watermarking and allow later 'dewatermarking', then assuming that you have your watermarking bitmap present at decoding time, you probably can do that. Sure you cannot use your initial approach - just simple merging of two layers is not reversible.
You need to use some reversible transformation, like rotating source image pixel RGB values vector, using watermark image pixel RGB values as parameters. While dewatermarking you just use negative values from watermark image.
Well, RGB vector is not ideal - you can go out of RGB space while rotating it. Probably you can find color space (or some other transformation in RGB space), better suited to your goal.
(English is not my first or even second language, thereby I apologize if you can't understand my idea - just ask over.)
Why don't you try to make it two layers of bitmap?
i wonder if you can use TIFF format, where you can store multiple images. that way on display you can choose to show with/without watermark.

C# - Image comparison (fast one)

At the moment I've got an database with over 100.000 images, they ain't the same size or anything like that but I want to make the following for my compagny:
I insert/upload an image and the system returns the image which is most likely the same. I don't know what algorithm to use but it needs to be fast. I can pre-process all the other images and put some info in the database which I use for the comparison.
Now what I want to know what the fastest way is to compare the images (with a good chance of being the same image). And what data I should save into the database (I could probably figure this one out myself if I got the algorithm).
It shouldn't take more then 5 minutes to compare the uploaded image to all the images in the database.
Thanks in advance!
Julian
Look at www.tineye.com, they have some kind of algorithm that I'm looking for. Guessing they use a very complex one, I just need one that does same thing but with lesser rate of succes.
The way I would do it is I'd generate a really small (say.. 1/50 of the original image size) image from every image you're comparing against, and store the thumbnail image path along with the original size in the database. I'd keep the thumbnails as uncompressed bmp's for speed and loss-free-ness (I just made that word up!), since they're so small anyway.
To compare your new image against the other ones, shrink it down by the same amount and compare it against the others pixel by pixel, with a certain threshold (say.. 10% difference from the original).
If it passes this test, you can do a full blown pixel by pixel compare against the original image.
edit: I just want to mention that I went down the probabilistic way before too. It worked OK, but building the meta data for the images took forever, and there were a lot of false positives. Instinctively, I think that calculating local averages for each grid rectangle of your image (which is what shrinking your image down does) would give similar, if not better results.
The best way for comparison is convert image to gray scale format and compare intensity of gray color. Its the fastest way used in real-time systems.
Also if you want to achieve higher qaullity and use colored images - use CIE 1994 or CIE 2000 as color difference formula

Categories

Resources