How to count how often a particular pattern repeats in an image












1














I have an image with multiple micro-QR codes. I want to count the number of micro-QR codes present in the image. I extracted the pattern of squares from single micro-QR (specifically called the location detection pattern). With the help of this pattern I want to count the micro-QRs in my image. Following is the code to convert a single QR code image to a matrix.



import cv2 
import PIL
import numpy

img = PIL.Image.open(path_of_the_image).convert("L")
imgarr = numpy.array(img)
imgarr1 = numpy.ndarray.flatten(imgarr)
print(imgarr)


enter image description here



this is the smaller reference matrix through which I want to count the micro-QR code in larger image.



 255 255 255 255 255 255 255 255 255

255 0 0 0 0 0 0 0 255
255 0 255 255 255 255 255 0 255
255 0 255 0 0 0 255 0 255
255 0 255 0 0 0 255 0 255
255 0 255 0 0 0 255 0 255
255 0 255 255 255 255 255 0 255
255 0 0 0 0 0 0 0 255

255 255 255 255 255 255 255 255 255









share|improve this question
























  • This should help - How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?.
    – Divakar
    Nov 13 at 5:45












  • Assuming the micro-QR codes are all the same size, exactly, in pixels, then you can take this detection pattern and compute a cross-correlation with the image. Points of high cross-correlation will be points where this pattern is located.
    – Cris Luengo
    Nov 13 at 5:45










  • 3 questions... 1) is your image a noise-free PNG, or a nasty scanned JPEG? 2) are the other micro-QR codes identical, or just similar insofar as they are also QR codes but for different things? 3) what's in the rest of the image - just white with other QR codes? Or patterns, text, photos?
    – Mark Setchell
    Nov 13 at 7:51










  • Possible duplicate of How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?
    – AndyK
    Nov 13 at 10:38










  • @MarkSetchell my image contains noise. all the micro qr codes are not identical. the rest of the image contain non white background as well. while the microqr codes are black and white with bit noise
    – sharayu salunkhe
    Nov 14 at 6:11
















1














I have an image with multiple micro-QR codes. I want to count the number of micro-QR codes present in the image. I extracted the pattern of squares from single micro-QR (specifically called the location detection pattern). With the help of this pattern I want to count the micro-QRs in my image. Following is the code to convert a single QR code image to a matrix.



import cv2 
import PIL
import numpy

img = PIL.Image.open(path_of_the_image).convert("L")
imgarr = numpy.array(img)
imgarr1 = numpy.ndarray.flatten(imgarr)
print(imgarr)


enter image description here



this is the smaller reference matrix through which I want to count the micro-QR code in larger image.



 255 255 255 255 255 255 255 255 255

255 0 0 0 0 0 0 0 255
255 0 255 255 255 255 255 0 255
255 0 255 0 0 0 255 0 255
255 0 255 0 0 0 255 0 255
255 0 255 0 0 0 255 0 255
255 0 255 255 255 255 255 0 255
255 0 0 0 0 0 0 0 255

255 255 255 255 255 255 255 255 255









share|improve this question
























  • This should help - How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?.
    – Divakar
    Nov 13 at 5:45












  • Assuming the micro-QR codes are all the same size, exactly, in pixels, then you can take this detection pattern and compute a cross-correlation with the image. Points of high cross-correlation will be points where this pattern is located.
    – Cris Luengo
    Nov 13 at 5:45










  • 3 questions... 1) is your image a noise-free PNG, or a nasty scanned JPEG? 2) are the other micro-QR codes identical, or just similar insofar as they are also QR codes but for different things? 3) what's in the rest of the image - just white with other QR codes? Or patterns, text, photos?
    – Mark Setchell
    Nov 13 at 7:51










  • Possible duplicate of How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?
    – AndyK
    Nov 13 at 10:38










  • @MarkSetchell my image contains noise. all the micro qr codes are not identical. the rest of the image contain non white background as well. while the microqr codes are black and white with bit noise
    – sharayu salunkhe
    Nov 14 at 6:11














1












1








1







I have an image with multiple micro-QR codes. I want to count the number of micro-QR codes present in the image. I extracted the pattern of squares from single micro-QR (specifically called the location detection pattern). With the help of this pattern I want to count the micro-QRs in my image. Following is the code to convert a single QR code image to a matrix.



import cv2 
import PIL
import numpy

img = PIL.Image.open(path_of_the_image).convert("L")
imgarr = numpy.array(img)
imgarr1 = numpy.ndarray.flatten(imgarr)
print(imgarr)


enter image description here



this is the smaller reference matrix through which I want to count the micro-QR code in larger image.



 255 255 255 255 255 255 255 255 255

255 0 0 0 0 0 0 0 255
255 0 255 255 255 255 255 0 255
255 0 255 0 0 0 255 0 255
255 0 255 0 0 0 255 0 255
255 0 255 0 0 0 255 0 255
255 0 255 255 255 255 255 0 255
255 0 0 0 0 0 0 0 255

255 255 255 255 255 255 255 255 255









share|improve this question















I have an image with multiple micro-QR codes. I want to count the number of micro-QR codes present in the image. I extracted the pattern of squares from single micro-QR (specifically called the location detection pattern). With the help of this pattern I want to count the micro-QRs in my image. Following is the code to convert a single QR code image to a matrix.



import cv2 
import PIL
import numpy

img = PIL.Image.open(path_of_the_image).convert("L")
imgarr = numpy.array(img)
imgarr1 = numpy.ndarray.flatten(imgarr)
print(imgarr)


enter image description here



this is the smaller reference matrix through which I want to count the micro-QR code in larger image.



 255 255 255 255 255 255 255 255 255

255 0 0 0 0 0 0 0 255
255 0 255 255 255 255 255 0 255
255 0 255 0 0 0 255 0 255
255 0 255 0 0 0 255 0 255
255 0 255 0 0 0 255 0 255
255 0 255 255 255 255 255 0 255
255 0 0 0 0 0 0 0 255

255 255 255 255 255 255 255 255 255






python numpy image-processing matrix






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 at 5:44









Cris Luengo

18.4k51947




18.4k51947










asked Nov 13 at 5:41









sharayu salunkhe

223




223












  • This should help - How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?.
    – Divakar
    Nov 13 at 5:45












  • Assuming the micro-QR codes are all the same size, exactly, in pixels, then you can take this detection pattern and compute a cross-correlation with the image. Points of high cross-correlation will be points where this pattern is located.
    – Cris Luengo
    Nov 13 at 5:45










  • 3 questions... 1) is your image a noise-free PNG, or a nasty scanned JPEG? 2) are the other micro-QR codes identical, or just similar insofar as they are also QR codes but for different things? 3) what's in the rest of the image - just white with other QR codes? Or patterns, text, photos?
    – Mark Setchell
    Nov 13 at 7:51










  • Possible duplicate of How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?
    – AndyK
    Nov 13 at 10:38










  • @MarkSetchell my image contains noise. all the micro qr codes are not identical. the rest of the image contain non white background as well. while the microqr codes are black and white with bit noise
    – sharayu salunkhe
    Nov 14 at 6:11


















  • This should help - How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?.
    – Divakar
    Nov 13 at 5:45












  • Assuming the micro-QR codes are all the same size, exactly, in pixels, then you can take this detection pattern and compute a cross-correlation with the image. Points of high cross-correlation will be points where this pattern is located.
    – Cris Luengo
    Nov 13 at 5:45










  • 3 questions... 1) is your image a noise-free PNG, or a nasty scanned JPEG? 2) are the other micro-QR codes identical, or just similar insofar as they are also QR codes but for different things? 3) what's in the rest of the image - just white with other QR codes? Or patterns, text, photos?
    – Mark Setchell
    Nov 13 at 7:51










  • Possible duplicate of How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?
    – AndyK
    Nov 13 at 10:38










  • @MarkSetchell my image contains noise. all the micro qr codes are not identical. the rest of the image contain non white background as well. while the microqr codes are black and white with bit noise
    – sharayu salunkhe
    Nov 14 at 6:11
















This should help - How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?.
– Divakar
Nov 13 at 5:45






This should help - How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?.
– Divakar
Nov 13 at 5:45














Assuming the micro-QR codes are all the same size, exactly, in pixels, then you can take this detection pattern and compute a cross-correlation with the image. Points of high cross-correlation will be points where this pattern is located.
– Cris Luengo
Nov 13 at 5:45




Assuming the micro-QR codes are all the same size, exactly, in pixels, then you can take this detection pattern and compute a cross-correlation with the image. Points of high cross-correlation will be points where this pattern is located.
– Cris Luengo
Nov 13 at 5:45












3 questions... 1) is your image a noise-free PNG, or a nasty scanned JPEG? 2) are the other micro-QR codes identical, or just similar insofar as they are also QR codes but for different things? 3) what's in the rest of the image - just white with other QR codes? Or patterns, text, photos?
– Mark Setchell
Nov 13 at 7:51




3 questions... 1) is your image a noise-free PNG, or a nasty scanned JPEG? 2) are the other micro-QR codes identical, or just similar insofar as they are also QR codes but for different things? 3) what's in the rest of the image - just white with other QR codes? Or patterns, text, photos?
– Mark Setchell
Nov 13 at 7:51












Possible duplicate of How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?
– AndyK
Nov 13 at 10:38




Possible duplicate of How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?
– AndyK
Nov 13 at 10:38












@MarkSetchell my image contains noise. all the micro qr codes are not identical. the rest of the image contain non white background as well. while the microqr codes are black and white with bit noise
– sharayu salunkhe
Nov 14 at 6:11




@MarkSetchell my image contains noise. all the micro qr codes are not identical. the rest of the image contain non white background as well. while the microqr codes are black and white with bit noise
– sharayu salunkhe
Nov 14 at 6:11

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274522%2fhow-to-count-how-often-a-particular-pattern-repeats-in-an-image%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274522%2fhow-to-count-how-often-a-particular-pattern-repeats-in-an-image%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

National Museum of Racing and Hall of Fame

Guess what letter conforming each word