0

Lets say you have a matrix like the following:

var map = 
[
[0,0,0,0,0,0],
[0,1,1,1,1,0],
[0,1,0,0,1,0],
[0,1,1,1,1,0],
[0,0,0,0,0,0],
[0,0,0,0,0,0],
];

What methods could be used to determine that there is a square of 1s inside of the matrix of 0s? What about multiple squares/rectangles offset to each other (Not overlapping, just potentially side by side)?

I'm sure that methods have already been made for such things, and I would love to learn about them.

Douglas Gaskell
  • 9,017
  • 9
  • 71
  • 128
  • I can help you please specify your real requirement.... – Piyush Barua Jul 13 '16 at 08:38
  • @piyushbarua I'm trying to find the bounds of squares or rectangles in a 2D array. The end result is to map the bounds of squares in the array and translate that to something else like a `canvas`, or HTML ``s. – Douglas Gaskell Jul 13 '16 at 08:49

1 Answers1

0

First of all, It is a kind of broad image processing question,

The concept can be named as shape numbers , shape numbering, object detection, OCR etc....,

You can use OpenCV library to detect shapes.

Try this question How to detect simple geometric shapes using OpenCV

--EDIT---

The ultimate numerical solution is using numerical edge detection and line thinning approaches like Canny, Robert Cross, Prewitt, Sobel operators and kernel, convolution matrix methodologies will help you.

All the above operators can be executed in software like Matlab, OpenCV .... etc

For JavaScript you can try using the following libraries

FabricJS http://fabricjs.com/

Orcad http://antimatter15.com/ocrad.js/demo.html

Shape-Detector https://github.com/MathieuLoutre/shape-detector

A neural network library

Brain https://github.com/harthur/brain

Demo for brain http://katspaugh.github.io/whiteboard/examples/brain/#rect

I think brain uses similar 1s and 0s in a matrix which can be more specific to your integer array

Community
  • 1
  • 1
Dickens A S
  • 3,824
  • 2
  • 22
  • 45
  • Most image processing I find is of literal images, and is usually very abstracted above this particular problem, not for finding a shape of similar data-points in a 2D array. Are those directly applicable, what should I try and find/look for more specific to this? – Douglas Gaskell Jul 13 '16 at 08:46