The control of line-edge or line-width roughness (LER/LWR) is a challenge, especially for future devices that are fabricated using extreme-ultraviolet (EUV) lithography. Accurate analysis of the LER/LWR plays an essential role in this challenge and requires the noise involved in scanning-electron-microscope (SEM) images to be reduced by appropriate noise filtering prior to analysis. To achieve this, we simulated the SEM images using a Monte Carlo method, and detected line edges in both experimental and theoretical images after noise filtering using new image-analysis software. The validity of this software and these simulations was confirmed by a good agreement between the experimental and theoretical results. In the case when the image pixels aligned perpendicular (crosswise) to line edges were averaged, the variance that was additionally induced by the image noise decreased with a number of averaged pixels, with exceptions when was relatively large, whereupon the variance increased. The optimal to minimize var() was formulated based on a statistical mechanism of this change. LER/LWR statistics estimated using the crosswise filtering remained unaffected when was smaller than the aforementioned optimal value, but monotonically changed when was larger contrary to expectations. This change was possibly caused by an asymmetric scan-signal profile at edges. On the other hand, averaging image pixels aligned parallel (longitudinal) to line edges not only reduced var() but smoothed real LER/LWR. As a result, the nominal variance of real LWR, obtained using simple arithmetic, monotonically decreased with a number of averaged pixels. Artifactual oscillations were additionally observed in power spectral densities. Var() in this case decreased in inverse proportion to the square root of according to the statistical mechanism clarified here. In this way, the noise filtering has a marked effect on the LER/LWR analysis and needs to be appropriately and carefully applied. These results not only constitute a solid basis, but also considerably improve previous empirical instructions for accurate analyses. The most important lesson from this work is to crosswise average an optimized number of image pixels consulting the aforementioned equation.