An embodiment according to the present invention includes a method for a machine-learning based approach to the formation of ultrasound and photoacoustic images. The machine-learning approach is used to reduce or remove artifacts to create a new type of high-contrast, high-resolution, artifact-free image. The method of the present invention uses convolutional neural networks (CNNs) to determine target locations to replace the geometry-based beamforming that is currently used. The approach is extendable to any application where beamforming is required, such as radar or seismography.