A recently introduced nonlinear pth root delay-and-sum (NL-p-DAS) beamforming (BF) technique for ultrasound (US) and photoacoustic (PA) imaging, achieving better spatial and contrast resolution compared to a conventional delay and sum (DAS) technique. While the method is advantageous for better resolution, it suffers from grainy speckles and dark areas in the image mainly due to the interference of non-sinusoidal functions. In this Letter, we introduce a modified NL-p-DAS technique called nonlinear pth root spectral magnitude scaling (NL-p-SMS), which performs the pth root on the spectral magnitude instead of the temporal amplitude. We evaluated the US and PA images of NL-p-SMS against those of NL-p-DAS by comparing the axial and lateral line profiles, contrasts, and contrast-to-noise ratios (CNRs) in both phantom and in vivo imaging studies with various p values. As a result, we found that the NL-p-SMS has better axial resolution and CNR than the NL-p-DAS, and reduces the grainy speckles and dark area artifacts. We believe that, with this enhanced performance, our proposed approach could be an advancement compared to the existing nonlinear BF algorithms.