It is so easy to understand the principle of this algorithm to quantify fractal dimension of a figure but I don't know where to start to write the code to implement that.
I have not implemented box counting dimension (i will denote it D1 further) myself, but it depends what you mean by "figure". Is it 2D picture? Or some multidimensional set of data?
Perhaps the simpliest case is black-and-white 2D pictrue. If it is not b/w you have to set some criterion which pixels/data are part of the object and which are not. Lets say your object is white on black background.
I would start by partitioning the picture to some large rectangular titles. (If your pictrue is 2048x1024 pixels you can start with four 1024x512 titles, then nine 682x341 titels, then sixteen 512x256 titles, etc.) Iterate the divisor so you get finer and finer cover.
For each division calculate two numbers, one used for upper estimate of D1 and one used for lower estimate of D1. Upper estimate is from number of "even partly white" titles. Lower estimate is from the number of "completly white without single black pixel" titles. Box counting dimension can be estimated from the slope of these numbers on the divisor.
This would be good start. Clever algorithm would bother with further subdividing titles which are already marked as completly black or completly white. They would remain so even after subdivision. Partitioning in 3, 4 or more dimensions is tedious as the number of boxes increases very quickly. If "being part of the object" is not question of being black or white pixel, you have to calculate some "member function" at the middle point of each title or box to determine its membership.
I have seen the code that calculate cox counting dimension of 2d picture in the formats of jpg,png and etc. the code is so undetermined as the picture scales change.