To find the best fit for $B=xA$,
you might formulate one of three seemingly equivalent cost functions:
$$\eqalign{
&(1)\;\quad &\min_x \;\|xA-B\|_F^2 \\
&(2)\;\quad &\min_x \;\|A-\tfrac{1}{x}B\|_F^2 \\
&(3)\;\quad &\min_x \;\|{\sqrt x}A-\tfrac{1}{{\sqrt x}}B\|_F^2 \\
}$$
each of which can be solved using the method that Rodrigo outlines for problem $(1)$
$$\eqalign{
&x_1 = \frac{\langle A,B\rangle}{\langle A,A\rangle},\quad
&x_2 = \frac{\langle B,B\rangle}{\langle A,B\rangle},\quad
&x_3
= {\rm sign}\Big(\langle A,B\rangle\Big){\sqrt\frac{\langle B,B\rangle}{\langle A,A\rangle}}
}$$
The advantage of the third formula is that it provides a usable value when the matrices are nearly perpendicular, i.e. $\langle A,B\rangle\sim 0.\,$ When the matrices are parallel, all three formula are identical. In any other situation, it's not obvious which formula is "better".
You could also multiply each side of the fit equation by a third matrix $M$, and solve for $x$.
$$\langle B,M\rangle=x\langle A,M\rangle \quad
\implies x=\frac{\langle B,M\rangle}{\langle A,M\rangle}$$
Note that setting $M\!=\!A$ yields $x_1$, while $M\!=\!B$ yields $x_2.\,$
Another sensible choice might be a matrix, each of whose elements equals the mean grayscale value. This is equivalent to swapping the Frobenius norm for the Manhattan norm.
Or set $M=\tfrac{1}{2}(A+B)$, which yields the mediant of $(x_1,x_2)$.