Why can't I get svg animatemotion to use absolute paths - animation

The SVG Path documentation states that using uppercase (M, L) letters means the coordinates are absolute. So in this path, it goes to absolute coordinates 100,100.
<rect x="200" y="0" width="30" height="15" style="stroke: #ff0000;">
<animateMotion path="M0,0 L100,100" begin="0s" dur="1s" repeatCount="indefinite" />
</rect>
But that does not seem to be true in reality. Here is a simple fiddle animating a rectangle. The starting points are at 200,0. If it moves to 100,100 then it should move down and left. It does not. It moves to the right. What's going on?
(My goal is to create an animation that moves through a series of absolute coordinates, and depending on user input, dynamically removes a coordinate, without throwing off the subsequent animations. Hence I need to use absolute coordinates.)

If you would like your coordinate system's origin to be set at (0,0) then you should define your rect element to be at (0,0), or x="0" y="0". After this, defining path="M200,0 L100,100" for your animateMotion will achieve your desired effect.
This is due to the fact that the coordinate system for SVG transforms is centered around the transforming element by default, so the coordinates (0,0) will be at the location where your element is defined. See the Coordinate System Transforms section of http://sarasoueidan.com/blog/svg-transformations/ for a write up on this.

The effect of a motion path animation is to add a supplemental transformation matrix onto the CTM for the referenced object which causes a translation along the x- and y-axes of the current user coordinate system by the computed X and Y values computed over time.
So if you want the object to go from 0,0 set x="0" rather than x="200"

Related

What is the minumum info you need to tell if an object is a circle?

So basically I have a program that runs through an image of objects and is supposed to count the number of cirlces. I can more or less accurately detect all objects and store the following results of each object:
Area(number of pixels), xPosition, YPosition and like the bounds.
I tried differentiating circles from non-circles by assuming every object was a circle, finding the radius and using pi*r^2 to get the area. If that area matched the number of pixels then it was a circle.
However this leads to a few errors. Such as when an object takes up the same area as a circle would but is not a circle.
Any idea's as to what I can try? It also fails in the noisy cases since my algorithm doesnt save pixels that are dark (Which is counted as like the background)
Edit: I cant use any already established algorithm such as the Hugh Transform
In theory, only the circles have a perimeter equal to the square root of 2π times the (filled) area. But you need an accurate assessment of the perimeter.
Alternatively, find the circle parameters (coordinates of the center and radius) by any method*, and check that the pixels of the contour fulfill the circle equation (compute the average deviations).
*If the shape is not a circle, those parameters will have "random" values, but this does not matter.

Find largest inscribed square with float point area in single color image

I want to find the largest inscribed square in single color image, which could be consists of discontinuous same color areas, for example below:
and then I have to find the largest inscribed blue square area
for this discontinues same color i must find the largest inscribed blue square area
now the current solution is "Maximum size square sub-matrix with all 1s"
First convert the picture to grayscale,and then convert matrix with 0 and 1, and calculate the largest square sub-matrix with all 1s,so we get the square region [left,top,size,size],for example, the first pink color photo 200x200, and then we get the blue square area [50,80,110,110]
as you can see, we can get the pixel range of largest inscribed square, But we get integer units. If the picture is small, we still get integer pixels, and the accuracy is definitely not enough,
I want to know if there is a way to figure out the float point area,for example
Suppose the picture size is 10x10
and then we can calculate the largest inscribed square below [2.56, 2.78, 3.25,3.25]:
if the picture is smaller, the float area is very useful,for example, if the inscribed square only have two unit, and the left and top begin is not start with integer, so we lost one unit accurate. if i want to put some text into the inscribed square, for example:
and then the position of the text which is locate in inscribed square is not precise enough!
I have been struggling with this issue for months,I tried opencv but there is no solution or function to meet my requirements And I know there must be good solution to solve this problem,but I have no idea! I don't know how to solve it, please help me, appreciate any prompt or tips
Also, I would like to add more information about my problem:
<svg id="_0110068" data-name="0110068" xmlns="http://www.w3.org/2000/svg" width="500" height="500" viewBox="0 0 500 500">
<path id="439.97_240.36_3.84_3.84" d="M435.9652,238.4672c.262,5.3118,7.7188,9.656,13.8857,8.1239C446.2334,242.0454,442.6965,237.6206,435.9652,238.4672Z" style="fill: #80d1c0"/>
</svg>
you can copy the svg and put it into this website and press Draw
then You can see a green block in the lower right corner
as you can seen, the
d = "M435.9652...Z" can be convert to picture, and the rect="439.97_240.36_3.84_3.84" is the largest inscribed square, that means
left = 439.97, top = 240.36 , right = left + 3.84, bottom = top + 3.84, so the size is 3.84 of the largest inscribed square, you can't omitted 0.84 that is very important! but how can i get the float point area

Interpreting paths in SVG files

I've generated a plain svg file using Inkscape containing three paths. Consider one of the paths inside the .svg file given below
<path xmlns="http://www.w3.org/2000/svg"
d="m 128.57143,243.79075
-2.85714,568.57143
474.28571,0
-31.42857,-611.42857 z" id="path2985"
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"/>
I want to parse this svg file to extract the XY coordinates of this closed path (it is closed because of the 'z' at the end of the coordinates list).
I am unsure how to interpret the 8 numbers. From what I understand, the first two numbers indicated by m 128.57143,243.79075 means that the path's origin is in screen-coordinates (not Cartesian!) at 128.57143 right and 243.79075 down from the top-left of the screen.
What about the rest of the 6 numbers? Do they indicate vectors in which to move relative to the previous point? Or just absolute screen coordinates?
As indicated in the SVG documentation here, SVG files usually have those M,L,H,...letters prefixed to each successive number pair which tells the vector-graphics viewer how to interpret that number pair while drawing that path.
In this case however, other than the m prefixed at the beginnnig and the z at the end there are no such letters in between. What then is the default behaviour in this case?
A capital letter M would suggest absolute coördinates. And a small m means relative coördinates. Since positioning is 0,0 by default, the first value of m would be identical to M.
Only the first coördinates are treated as 'm' (=moveto). The next ones are treated as 'l' (=lineto). Since 'm' was not capitalised the next coördinate will be treated as relative.
It would be the same as:
<path xmlns="http://www.w3.org/2000/svg"
d="m 128.57143,243.79075
l-2.85714,568.57143
474.28571,0
-31.42857,-611.42857 z" id="path2985"
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"/>
For the sake of reference: this is what the spec sais about the moveto command. (source: https://www.w3.org/TR/SVG/paths.html#PathDataMovetoCommands)
Start a new sub-path at the given (x,y) coordinate. M (uppercase)
indicates that absolute coordinates will follow; m (lowercase)
indicates that relative coordinates will follow. If a moveto is
followed by multiple pairs of coordinates, the subsequent pairs are
treated as implicit lineto commands. Hence, implicit lineto commands
will be relative if the moveto is relative, and absolute if the moveto
is absolute. If a relative moveto (m) appears as the first element of
the path, then it is treated as a pair of absolute coordinates. In
this case, subsequent pairs of coordinates are treated as relative
even though the initial moveto is interpreted as an absolute moveto.

SVG transform=Matrix(a,b,c,d,e,f) on width and height

(this should probably be in another community but I couldn't find how to move the question)
I was told for an SVG I have that one of the transformations in it is an illegal or invalid transformation. I believe I have found the offending transformation and am trying to understand what it did.
The transformation is:
<image transform="matrix(0.773723,0,0,0,860,182)" width="137" height="2" xlink:href="someImage.png" />
From my understanding, the SVG notation of the matrix (0.773723,0,0,0,860,182) is the equivalent of (pretend its one big bracket not 3 on each side):
[.773723,0,0860]
[0,0,182 ]
[0,0,1 ]
My research has lead me to believe I am to use the width and height after the matrix, convert it into matrix notation and multiply the two to understand how it was transformed. If that is correct, I'm trying to understand how to convert the height and width to the matrix notation []. If it is not correct, any pointers in the right direction would be greatly appreciated!
That looks like a legal transform (technically). but it's incorporating a 0% vertical scale: that "0" in the fourth position of the matrix, so it's making your element disappear. Height and width are the "before" height and width, not the "after" height and width. You can't specify absolute dimensions in a matrix, just scaling factor. (You can specify offset or translate in absolute dimensions).

Detect a shape as a circle with Matlab

I am writing a program in Matlab to detect a circle.
I've already managed to detect shapes such as the square, rectangle and the triangle, basically by searching for corners, and determining what shape it is based on the distance between them. The images are black and white, with black being the background and white the shape, so for me to find the corners I just have to search each pixel in the image until I find a white pixel.
However I just can't figure out how I can identify the circle.
Here it the an example of how a circle input would look like:
It is difficult to say what the best method is without more information: for example, whether more than one circle may be present, whether it is always centred in the image, and how resilient the algorithm needs to be to distortions. Also whether you need to determine the location and dimensions of the shape or simply a 'yes'/'no' output.
However a really simple approach, assuming only one circle is present, is as follows:
Scan the image from top to bottom until you find the first white pixel at (x1,y1)
Scan the image from bottom to top until you find the last white pixel at (x2,y2)
Derive the diameter of the suspected circle as y2 - y1
Derive the centre of the suspected circle as ((x1+x2)/2, y1+(y2-y1)/2)
Now you are able to score each pixel in the image as to whether it matches this hypothetical circle or not. For example, if a pixel is inside the suspected circle, score 0 if it is white and 1 if it black, and vice-versa if it is outside the suspected circle.
Sum the pixel scores. If the result is zero then the image contains a perfect circle. A higher score indicates an increasing level of distortion.
I think you may read about this two topics:
Theoretical:
Binary images
Hough transform
Matlab:
Circle Detection via Standard Hough Transform
Hough native in matlab
Binary images

Resources