question

user-806 avatar image
user-806 asked

How to compare images in Access

Hi, CAn any body tell em how to compare two images in Accessc.Actually I have Photo filed filed datatype is oleobject which stores images.Now i want to know how may duplicate images is there. Thanks in advance
microsoft-access
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Fatherjack avatar image
Fatherjack answered
How do you want to compare them, as a binary file or as a side-by-side view of the images? Are the images stored on a file server too? There are plenty of file comparison tools that could parse a directory and give you the results...
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

user-806 avatar image user-806 commented ·
I want to compare side by side view.Images are not stored on file server.
0 Likes 0 ·
WilliamD avatar image WilliamD commented ·
But side by side comparison will be painfully slow compared to an automated comparison. However, you could create a form that loads two images from the database - one image that remains constant and the second would be used to load a comparison image and then allow you to mark it as a duplicate.
0 Likes 0 ·
WilliamD avatar image
WilliamD answered
You could try generating a hash of the binary data and comparing that for each entry in your table. As it is Access, you could do that in VB. I have no idea how inefficient that would be though, most probably not very. It would be better to do it as Fatherjack mentioned by using a comparison tool on a directory structure - there are lots of free versions available and most should be fast enough.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Magnus Ahlkvist avatar image
Magnus Ahlkvist answered
I would start off creating a query comparing datasize of the OLE Objects. I believe that can be done using the **LenB**-function. Create a query that does **GROUP BY LenB(OLEField) HAVING COUNT(*)>1**. That would limit the number of objects you need to compare. Next step would be to open the query from a VBA-Module, and compare the rows with identical sizes for the OLE Object. Comparing two objects can be done by storing them in Byte arrays, and using **StrConv** function to compare them. Here's a VBA function that could possibly be used for that purpose. Function OleObjectEquals(a() As Byte, b() As Byte) As Boolean If StrConv(a, vbUnicode) = StrConv(b, vbUnicode) Then OleObjectEquals = True Else OleObjectEquals = False End If End Function
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

TimothyAWiseman avatar image
TimothyAWiseman answered
It largely depends on what you mean by compare. If you just want to see if the images are identical in a byte for byte since and you really want to use Access, then I think Magnus has the best answer you will find. With that said, Access is probably not a good tool for this task unless you have some truly compelling reason to use it. I personally would consider Python where you have access to bsdiff ( [ http://www.daemonology.net/bsdiff/][1] ) and difflib ( [ http://docs.python.org/library/difflib.html] [2] ) either of which will provide you a comparison very effeciently and with a minimum of code. C# would also be a good choice for that and Microsoft very helpfully provides a full tutorial for doing it effeciently at [ http://support.microsoft.com/default.aspx?scid=kb;EN-US;320348][2] Now, if you mean you want the program to do a sophisticated analysis to tell you the amount of difference, then Access is certainly not the right tool and you will be far outside my knowledge. And finally, if you want to provide the two pictures side by side so that the user can personally compare them, then just create two image objects in your form. Then you can use VBA to change the images they have. The code to change the image is as simple as: ImageName.Picture = "Drive:\Path\File.jpg" You can of course include that in a more sophisticated procedure that decide which pictures to show the user. [1]: http://www.daemonology.net/bsdiff/ [2]: http://support.microsoft.com/default.aspx?scid=kb;EN-US;320348
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.