10
$\begingroup$

This is a recreational question. At my workplace within the same stairwell there are different steps numbers per floor on certain floors.

I have tried to automate counting the steps by binarising the image (Binarize and Dilation, Erosion, DeleteSmallComponents) to minimize lines. ImageLines, ImageCorners and GradientOrientahitionFilter did not yield helpful results (this is most likely my lack of experience and understanding). I have not tried AI queries.

I can manually count the steps (as it is a small number of points):

enter image description here

pts = {{2118, 4821}, {2041, 4657}, {1933, 4478}, {1820, 4242}, {1718, 4001}, {1590, 3739}, {1456, 3452}, {1261, 3118}, {1072, 2713}, {805, 2236}, {533, 1687}, {164, 1056}} Show[i, Graphics[{Red, PointSize[0.02], Point[pts], MapThread[ Text[Style[#1, Bold], #2, {0, -3}] &, {Range[Length[pts]], pts}]}, ImageSize -> ImageDimensions[i]]] 

enter image description here

The other example: enter image description here

pts2 = {{1194, 3120}, {1173, 3011}, {1151, 2921}, {1111, 2834}, {1082, 2733}, {1050, 2628}, {999, 2476}, {955, 2309}, {879, 2103}, {807, 1889}, {742, 1578}, {626, 1241}, {477, 777}}; Show[i2, Graphics[{Red, PointSize[0.02], Point[pts2], MapThread[ Text[Style[#1, Bold], #2, {1, -4}] &, {Range[Length[pts2]], pts2}]}, ImageSize -> ImageDimensions[i2]]] 

enter image description here

I did not post my attempts other than the above as they were not edifying and it would be too messy.

$\endgroup$
4
  • 1
    $\begingroup$ Isn't there some AI that would do that? With request count number of stairs in this image. If not then AI does not deserve that second character "I" in its name. $\endgroup$ Commented Sep 3 at 9:12
  • $\begingroup$ @azerbajdzan It is not that I cannot formulate prompt and upload an image (asking it do it in Wolfram Language). I have worked for this institution for 10 years (after 30 years at another). I have counted the stairs on “countless occasions” and don’t need. I just thought as a question it may inspire human answers that would teach me. Finally, for a number of reasons I don’t pay for AI and my limited use of free versions have not been useful (with some exceptions). I do accept your point. $\endgroup$ Commented Sep 3 at 9:55
  • 1
    $\begingroup$ I wonder if you wouldn't get along better if instead of standing at the bottom looking up you stood at the top looking down. From what you've posted I can see, when looking down, a series of alternating black and white (-ish) stripes. $\endgroup$ Commented Sep 3 at 14:31
  • $\begingroup$ CornerFilter[img,20] // ImageAdjust // Binarize seems like it could be a good start, as it picks up the edges where each stair meets the wall pretty well (although it also is still picking up a lot of non-stair things as well). $\endgroup$ Commented Sep 3 at 15:16

1 Answer 1

4
$\begingroup$

Here is some progress (thank you @ydd):

img = CornerFilter[i, 40] // ImageAdjust // Binarize (* as per ydd*) id = ImageDimensions[i] it = ImageTake[img, {1, 0.84 id[[2]]}, {1, id[[1]]/1.8}] (* crop image *) sel = SelectComponents[it,#Area>300&] (* remove a small component *) seld = Dilation[sel, DiskMatrix[{40, 100}]] (* merge the same corners *) compc = ComponentMeasurements[seld, "Centroid"]; (* counting *) check = Show[seld, Graphics[{Red, PointSize[0.02], Point[compc[[All, 2]]]}]] soln = Show[ImageTake[i, {1, 0.84 id[[2]]}, {1, id[[1]]/1.8}], Graphics[{Red, PointSize[0.02], Point[compc[[All, 2]]]}], PlotLabel -> Row[{"There are ", Length[compc], " steps"}]] 

The steps are summarised below:

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.