Let $E$ be a measurable subset of $\mathbb{R}^n$, and $mE<\infty$. $f(x)$ is a bounded measurable function almost everywhere. I want to find such a function $g$.
For $n=1$, i.e., $E\in\mathbb{R}$. $\forall \varepsilon>0$, $\exists F_\varepsilon\subset E$ a closed set, such that $f(x)$ is continuous on $F_\varepsilon$. We write $E-F_\varepsilon=\bigcup\limits_{i=1}^\infty (a_i,b_i)$. I can define that $$g(x)= \begin{cases} f(x), & x\in F_\varepsilon,\\ f(a_i)+\frac{f(b_i)-f(a_i)}{b_i-a_i}(x-a_i), & x\in(a_i,b_i). \end{cases}$$ It is easy to check that $g(x)$ satisfies the condition.
But how about the case $n>1$? How to define such a function $g(x)$? It seems almost entirely different from last case since it is hard to choose such two points "$a_i$, $b_i$" for $n>1$.
It is a special case of the Tietze extension theorem. We can solve this question in a way similar to the proof of the Tietze extension theorem.
By Lusin, $\forall \varepsilon>0$, $\exists F_\varepsilon\subset E$ a closed set, s.t. $f(x)$ is continuous on $F_\varepsilon$ and $m(E-F_\varepsilon)$. Then $\forall x\in F_\varepsilon$, $\exists M>0$, s.t. $|f(x)|<M$. Let $$A=F_\varepsilon[x\mid \frac{M}{3}\le f(x)\le M],\ B=F_\varepsilon[x\mid -M\le f(x)\le -\frac{M}{3}],\ C=F_\varepsilon[x\mid -\frac{M}{3}\le f(x)\le \frac{M}{3}],$$ and $$g_1(x)=\frac{M}{3}\frac{d(x,B)-d(x,A)}{d(x,B)+d(x,A)},$$ which is almost entirely different from the case on $\mathbb{R}$. $\forall x,y\in\mathbb{R}^n$, $\exists z\in A$, s.t. $d(y,A)+\varepsilon>|y-z|$. Then $$d(x,A)\le |x-z|\le |x-y|+|y-z|<|x-y|+d(y,A)+\varepsilon.$$ For $\varepsilon$ arbitrary, $d(x,A)-d(y,A)\le |x-y|$, and then $|d(x,A)-d(y,A)|\le |x-y|$, which means that $d(x,A)$ is uniform continuous on $\mathbb{R}^n$, and $g_1(x)$ is continuous on $\mathbb{R}^n$. Since $|g_1(x)|\le\frac{M}{3}$ on $\mathbb{R}^n$, $|f(x)-g_1(x)|\le\frac{2M}{3}$. By induction, $|g_2(x)|\le\frac{2M}{3^2}$ on $\mathbb{R}^n$, $|f(x)-g_1(x)-g_2(x)|\le\left(\frac{2}{3}\right)^2M$ on $F_\varepsilon$. Then we can get a function sequence such that $$|g_k(x)|\le\frac{1}{3}\left(\frac{2}{3}\right)^{k-1}M,\ x\in\mathbb{R}^n;\\\left|f(x)-\sum_{i=1}^kg_i(x)\right|\le\left(\frac{2}{3}\right)^kM,\ x\in F_\varepsilon.$$ For the first inequation, by Weierstrass M-test, $\sum\limits_{k=1}^\infty g_k(x)$ uniformly converges. We write $g(x)=\sum\limits_{k=1}^\infty g_k(x)$. For the second inequation, we find that $f(x)=\sum\limits_{k=1}^\infty g_k(x)$ on $F_\varepsilon$. Since $$|g(x)|\le\sum\limits_{k=1}^\infty |g_k(x)|\le\sum\limits_{k=1}^\infty \frac{M}{3}\left(\frac{2}{3}\right)^{k-1}=M,$$ $g(x)$ is continuous on $\mathbb{R}^n$ and $f(x)|_{F_\varepsilon}=g(x)$.