Click here to Skip to main content
15,905,782 members
Please Sign up or sign in to vote.
3.50/5 (4 votes)
See more:
Is there a way to find if a small Image is part of a larger one using vb.net code ?

thanks in advance !
Posted
Comments
Sergey Alexandrovich Kryukov 29-May-11 13:53pm    
Good question, my 5, but I don't think there is an easy and effective solution.
Important question: is it ***exact*** copy of the small image?

If so, the solution can be pretty simple, but it's hard to make if fast.
--SA
[no name] 31-May-11 12:51pm    
yes ! the small image is copied from within the big one .
however, I still have a problem ( look at my reply to Dave Kreskowiak)

1 solution

If you're looking for an exact pixel-by-pixel copy of the smaller image in the alrger one, then it's not that hard. It's just a matter of looking for the first pixel to search for in the image, then, when/if found, looking at the adject pixels.

If you're looking for any kind of scaling or rotation of the image to search for in the larger image, now you've got an extremely difficult problem in "machine vision". Happy researching!
 
Share this answer
 
Comments
[no name] 30-May-11 1:51am    
Thanks You !
You help me so much !
[no name] 31-May-11 10:15am    
well... I tried it and I have some problems !
when I try this code:
[code]
Dim smallpix As Color = small.GetPixel(1, 1)
Dim i_heigh As Integer = 0, i_width As Integer = 0

For i_width = 0 To big.Width - 1

For i_height = 0 To big.Height - 1
Dim bigpix As Color = big.GetPixel(i_width, i_heigh)

If smallpix = bigpix Then
MsgBox("THE SAME !")

End If
Next
Next

[/code]
I get about of 70 similar pixels !

but when I do this :
[code]
Dim smallpix As Color = small.GetPixel(1, 1)
Dim i_heigh As Integer = 0, i_width As Integer = 0

For i_width = 0 To big.Width - 1

For i_height = 0 To big.Height - 1
Dim bigpix As Color = big.GetPixel(i_width, i_heigh)




If smallpix = bigpix Then
MsgBox("THE SAME !")
If small.GetPixel(2, 1) = big.GetPixel(i_width + 1, i_heigh) Then
MsgBox("THE SAME !!!!!!!")

End If

End If
Next
Next
[/code]

" MsgBox("THE SAME !!!!!!!") " command is never reached !
why is that ?
I am sure that the small image is part of the large one because I cropped it from there !
so I guess the problem will be somewhere in my code !!

Can you help please ???
Dave Kreskowiak 31-May-11 18:51pm    
It doesn't work because you never get anything from the small image other than the first and second pixels. You need an index into the image in order to match the same pixels.

Your inner and outer loops are also too big. Think about it. You're not going to look for the pixel in the top left corner in the bottom right corner of the big image, are you? You make the loops smaller than the biggest dimensions of the large image by an amount equal to the size of the smaller image.

Now, when you do find the first pixel from the small image, you can switch to a smaller set of loops that are the size of the smaller image. Then you can use those offsets as offsets into the larger image to get the pixels.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900