Save a list of elements inside an image in c# - 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.

Related

Can't find part of image in original

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.

Accessing objects in an array based on corresponding object in another array

I've recently started coding and I'm trying to make minesweeper with windows forms.
I have an array, like so:
tiles = new PictureBox[30,16];
I also have another array, like this:
mines = new int[30,16];
The code for generating the grid of pictureboxes and randomizing the mines works.
I randomize where to put the mines in a separate method and store the locations in the mines array. Now I want a way to access the element in the mines array that corresponds to the index in the picturebox array so that I can calculate what is in that tile.
Anyone have any ideas if this is possible? I have considered using the picturebox.name property to track whether or not there is a mine in a certain tile, but I'm unsure of what effect the name property has. I could probably do it by calculating the coordinates of the mouseclick but I would really like to avoid that.
Any help would be greatly appreciated.
You can use Tag for storing data that you need, for example you can save a Tuple<int,int> in Tag so when a picture box is clicked you can retreive it via ((sender as PictureBox).Tag as Tuple<int,int>) in OnClick event handler, then you know this picture box is in which row and in which column,
Do not forget to assign Tag when you are populating your tiles array

How to create an image with multiple tiles in the background?

I would like to know how I can create one image from many. I would like to create a tile in my windows phone application like in this image (specifically, the People tile):
(source: addictivetips.com)
I have nine pictures, and I would create an image, that I will add like tile to background. Does anybody know how can I create an image that looks like the one in that picture?
I have very little experience in this space, but have you considered creating a control that simply displays up to 9 pictures side by side in a grid like that? You then can bind each image independently & change them out however you want. This article touches on how to bind phontos in WP7 nicely:
http://msdn.microsoft.com/en-us/library/hh286418(v=vs.92).aspx
If you're talking about assembling an actual graphic image like a jpeg or bitmap, you'll need to look at the Image Class, Bitmap Class, and Graphics Class. Essentially you'll need to implement the following steps:
Load the relevant images with From method in Image, typically Image.FromFile.
Determine how many rows and columns you'll be using.
Calculate the total width and height for your layout using the widths and heights of the loaded images with appropriate padding added.
Create a new Bitmap of the appropriate size with the correct background color and iamge format.
Have variables for the current drawing location (x & y).
Have variables for the current row and column in your layout.
In a loop, Create your Graphics object.
Use Graphics.DrawImage to add your loaded image to the layout bitmap.
Increment your drawing row and or column as appropriate.
Calculate your new drawing location.
Repeat until done.
One of the options is to use WriteableBitmapEx
Also you can probably find an answer to your question here: How can I merge two images into one?

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