Commit 2567d078169567a951da60ecd4712366802e6e95

That should not have been so difficult.
c/azier.c
(1 / 1)
  
1515
1616 arguments = &arguments[1];
1717
18 if (!azy_do_everything(arguments, count, /* 256 * 256 */ 256 * 1024, 8)) {
18 if (!azy_do_everything(arguments, count, /* 256 * 256 */ 256 * 1024, 6)) {
1919 fputs("Failure!\n", stdout);
2020 return EXIT_FAILURE;
2121 }
c/azy.c
(39 / 24)
  
3434
3535// The following procedures may mangle their outputs in case of a failure.
3636
37bool azy_icp(CvMat* result_, // Icp means iterative closest point.
37bool azy_icp(CvMat* result_, // Icp means iterative closest point, eventually.
3838 CvSeq* fixed,
3939 CvSeq* moving,
4040 CvMat* best_guess) {
6363 cvSet2D(mmat, (int )index, 0, cvScalarAll(x));
6464 cvSet2D(mmat, (int )index, 1, cvScalarAll(y));
6565 }
66 cvFindHomography(fmat, mmat, result_, CV_RANSAC, 3, NULL);
66 cvFindHomography(fmat, mmat, result_, CV_LMEDS, 3, NULL); // This sucks.
6767
6868 return true;
6969}
221221 struct position const* const p3,
222222 double const ac,
223223 double const ai,
224 double const rfree) {
225 double const q2 = 2 * ((p0->y - p3->y) * t0->x
226 + (p3->x - p0->x) * t0->y
227 + (p0->y - p3->y) * t3->x
228 + (p3->x - p0->x) * t3->y);
229 double const q3 = t0->y * t3->x - t0->x * t3->y;
224 double const rfree,
225 double const rindet) {
226 double const q1 = 20 * (ac - ai);
227 double const q2 = 6 * (t0->x * (p0->y - p3->y)
228 + t0->y * (p3->x - p0->x)
229 + t3->x * (p0->y - p3->y)
230 + t3->y * (p3->x - p0->x));
231 double const q3 = 3 * (t0->y * t3->x - t0->x * t3->y);
230232 double r;
231 if (q3 == 0)
232 r = rfree;
233 else
234 r = -q2 / q3;
233 if (q1 == 0) {
234 if (q3 == 0)
235 r = rfree;
236 else
237 r = -q2 / q3;
238 } else {
239 double const d = q2 * q2 - 4 * q1 * q3;
240 double const m = -1 / (2 * q3);
241 if (d < 0)
242 r = rindet;
243 else if (d == 0)
244 r = q2 * m;
245 else { // Which one to choose?
246 double const s = sqrt(d);
247 r = fmax((q2 + s) * m,
248 (q2 - s) * m);
249 }
250 }
235251
236252 *result_ = r;
237253
496496 cvAddWeighted(synonym.pixels, 0.5, safe.pixels, 1, 0, synonym.pixels);
497497 if (index2 == 0) {
498498 say("Look at this outline.");
499 show(&synonym);
499 // show(&synonym);
500500 }
501501
502502 azy_destroy_colorful_image_(&safe);
679679 }
680680
681681 // Otherwise...
682 double const focal_factor = 0.25;
682 double const focal_factor = 0.5;
683683 say("About to iterate again.");
684684 for (size_t index = 0, index2 = 0;
685685 index < path_count;
699699 size_t const end_index = (blob->clip_index + blob->clip_span) % total;
700700 size_t const start_focus_index = (start_index + focus) % total;
701701 size_t const end_focus_index = (end_index - focus + total) % total;
702 say("Clip indices %zu, %zu and focused %zu, %zu.",
703 start_index, end_index, start_focus_index, end_focus_index);
702 say("Clip and focus indices %zu, %zu, %zu, %zu.",
703 start_index, start_focus_index, end_focus_index, end_index);
704704 CvPoint* start = (CvPoint* )CV_GET_SEQ_ELEM(CvPoint, blob_contours[index2][index3], start_index);
705705 CvPoint* end = (CvPoint* )CV_GET_SEQ_ELEM(CvPoint, blob_contours[index2][index3], end_index);
706706 CvPoint* start_focus = (CvPoint* )CV_GET_SEQ_ELEM(CvPoint, blob_contours[index2][index3], start_focus_index);
707707 CvPoint* end_focus = (CvPoint* )CV_GET_SEQ_ELEM(CvPoint, blob_contours[index2][index3], end_focus_index);
708 say("Focusing through (%d, %d), (%d, %d), (%d, %d), (%d, %d).",
709 start->x, start->y,
710 start_focus->x, start_focus->y,
711 end_focus->x, end_focus->y,
712 end->x, end->y);
708713 CvPoint start_tangent = {
709714 .x = start->x * 2 - start_focus->x,
710715 .y = start->y * 2 - start_focus->y
718718 .x = end->x * 2 - end_focus->x,
719719 .y = end->y * 2 - end_focus->y
720720 };
721 say("Bezier through (%d, %d), (%d, %d), (%d, %d), (%d, %d).",
722 start->x, start->y,
723 start_tangent.x, start_tangent.y,
724 end_tangent.x, end_tangent.y,
725 end->x, end->y);
726721 struct position starter = {
727722 .x = (double )start->x,
728723 .y = (double )start->y
740740 say("Normal vectors (%f, %f), (%f, %f).",
741741 start_normal.x, start_normal.y,
742742 end_normal.x, end_normal.y);
743 double const ac = rln * 1.25; // Just for testing.
743744 double const ai = partial_blob_sizes[index2][index3];
744 double const ac = rln * 1.1; // Just for testing.
745745 double radius;
746746 say("Guessing for areas %f and %f.", ai, ac);
747747 azy_guess_radius(&radius, &starter, &start_normal, &end_normal, &ender,
748 ac, ai, 1);
748 ac, ai, 0, 0);
749749 say("Fun radius %f.", radius);
750 radius = 100;
751750 // Some heuristic.
752751 double ass;
753752 some_distance_thing(&ass, start, end);
c/makefile
(7 / 3)
  
4242# ../../samples/019-5/l_1397038164_65.png \
4343# ../../samples/019-5/l_1397038164_82.png \
4444# #
45 # expected 12 -> 28
46 # 1.02 0.13 -7.5
47 # -0.26 1.09 297.5
48 # -0.00000 -0.00008 1.0
4549 - ./azier \
46 ../../samples/061-1/l_1396438664_12.png \
47 ../../samples/061-1/l_1396438664_28.png \
48 # \
50 /tmp/l_1396438664_12.png \
51 /tmp/l_1396438664_28.png \
52# # \
4953# ../../samples/061-1/l_1396438663_97.png \
5054# ../../samples/061-1/l_1396438664_12.png \
5155# ../../samples/061-1/l_1396438664_28.png \
log/log.tex
(19 / 18)
  
130130 & = \fullint t C^y(t) \fulld t C^x(t)
131131 % = -\fullint t C^x(t) \fulld t C^y(t)
132132 = \fullint t \Big(B^y(t) \fulld t B^x(t) - L^y(t) \fulld t L^x(t)\Big) \\
133 & = \frac 3{20} \big(3 (P_1^x P_4^y
133 \frac{20} 3 A_r
134 & = 3 (P_1^x P_4^y
134135 - P_1^y P_4^x) + 2 (P_1^y P_2^x
135136 - P_1^x P_2^y
136137 + P_3^y P_4^x
141141 + P_2^y P_3^x
142142 - P_2^x P_3^y
143143 + P_2^y P_4^x
144 - P_2^x P_4^y)\big) \\ % Looks like a determinant.
145 & = \frac 3{20} \bigg(3 \det\begin{bmatrix}
144 - P_2^x P_4^y) \\ % Looks like a determinant.
145 & = 3 \det\begin{bmatrix}
146146 P_1^x & P_1^y \\
147147 P_4^x & P_4^y
148148 \end{bmatrix}
162162 \end{bmatrix} + \det\begin{bmatrix}
163163 P_3^x & P_3^y \\
164164 P_2^x & P_2^y
165 \end{bmatrix}\bigg).
165 \end{bmatrix}.
166166\end{align*}
167167Is this structure from group theory?
168168Either way substituting $P_2 = P_1 + r \bar T_1$ and
191191 P_1^x + r \bar T_1^x & P_1^y + r \bar T_1^y
192192 \end{bmatrix}.
193193\end{align*}
194Now we must expand it again.
194195Anyway if $A_c$ is the complete area and $A_i$ the incomplete area,
195196the added area $A_r$ must satisfy
196197\begin{align*}
197198 A_c
198199 & = A_i + A_r
199200 \Leftrightarrow \\
200 \frac{20} 3 (A_c - A_i) - \frac{20} 3 A_r
201 20 (A_c - A_i) - 20 A_r
201202 & = Q_1 + r Q_2 + r^2 Q_3
202203 = 0
203204 \Leftrightarrow \\
204205 r
205 & = -\frac{Q_2 \pm \sqrt{Q_2^2 - 4 Q_1 Q_3}}{2 Q_1},
206 & = -\frac{Q_2 \pm \sqrt{Q_2^2 - 4 Q_1 Q_3}}{2 Q_3},
206207\end{align*}
207208where
208209\begin{align*}
209 Q_1
210 & = 0 \\
211 Q_2
212 & = \frac 3{10} ((P_1^y - P_4^y) \bar T_1^x
213 + (P_4^x - P_1^x) \bar T_1^y
214 + (P_1^y - P_4^y) \bar T_4^x
215 + (P_4^x - P_1^x) \bar T_4^y) \\
216 Q_3
217 & = \frac 3{20} (\bar T_1^y \bar T_4^x
218 - \bar T_1^x \bar T_4^y).
210 \frac 1{20} Q_1
211 & = A_c - A_i \\
212 \frac 1 6 Q_2
213 & = \bar T_1^x (P_1^y - P_4^y)
214 + \bar T_1^y (P_4^x - P_1^x)
215 + \bar T_4^x (P_1^y - P_4^y)
216 + \bar T_4^y (P_4^x - P_1^x) \\
217 \frac 1 3 Q_3
218 & = \bar T_1^y \bar T_4^x
219 - \bar T_1^x \bar T_4^y.
219220\end{align*}
220221Does it always have a solution (as in $Q_2^2 \ge 4 Q_1 Q_3$)?
221Indeed it does, because $Q_1 = 0$.
222Therefore either $r = 0$, which is ridiculous, or
222If $Q_1 = 0$ then either $r = 0$, which is ridiculous, or
223223\begin{align*}
224224 Q_2 + r Q_3
225225 & = 0
log/stuff.mac
(8 / 8)
  
2222 P_2_y = P_1_y + r * bar_T_1_y,
2323 P_3_y = P_4_y + r * bar_T_4_y;
2424R : rat(A_r_prime, r);
25Q : [coeff(R, r, 0),
25Q : [A_c - A_i - coeff(R, r, 0),
2626 coeff(R, r, 1),
2727 coeff(R, r, 2)];
28Q_prime : 3 * [0,
29 2 * ((P_1_y - P_4_y) * bar_T_1_x
30 + (P_4_x - P_1_x) * bar_T_1_y
31 + (P_1_y - P_4_y) * bar_T_4_x
32 + (P_4_x - P_1_x) * bar_T_4_y),
33 bar_T_1_y * bar_T_4_x
34 - bar_T_1_x * bar_T_4_y] / 20;
28Q_prime : [20 * (A_c - A_i),
29 6 * ((P_1_y - P_4_y) * bar_T_1_x
30 + (P_4_x - P_1_x) * bar_T_1_y
31 + (P_1_y - P_4_y) * bar_T_4_x
32 + (P_4_x - P_1_x) * bar_T_4_y),
33 3 * (bar_T_1_y * bar_T_4_x
34 - bar_T_1_x * bar_T_4_y)];