How to count how often a particular pattern repeats in an image
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)

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
add a comment |
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)

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
This should help -How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?.
– Divakar
Nov 13 '18 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 '18 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 '18 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 '18 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 '18 at 6:11
add a comment |
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)

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
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)

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
python numpy image-processing matrix
edited Nov 13 '18 at 5:44
Cris Luengo
19.3k51947
19.3k51947
asked Nov 13 '18 at 5:41
sharayu salunkhesharayu salunkhe
244
244
This should help -How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?.
– Divakar
Nov 13 '18 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 '18 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 '18 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 '18 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 '18 at 6:11
add a comment |
This should help -How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?.
– Divakar
Nov 13 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 6:11
add a comment |
0
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
This should help -
How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?.– Divakar
Nov 13 '18 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 '18 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 '18 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 '18 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 '18 at 6:11