The Samsung Galaxy S4 comes with a 13MP main camera and a 2MP secondary camera and the two can be used at the same time.
The Sony Xperia Z features the new Sony Exmor RS sensor, also 13MP, and has a 2MP front facing camera as well. Unfortunately those two can't be used simultaneously.
First, let's talk Field of View (FoV), how much each camera captures. According to EXIF info, the Samsung Galaxy S4 camera is a 31mm (in 35mm equiv.), while the Sony Xperia Z is wider at 28mm. The difference is noticeable, but not too big a deal.
The Samsung Galaxy S4 captures very good amounts of fine detail (see bricks, wall texture, foliage) and the noise level is relatively low (check the sky). It shows oversharpening halos here and there, but no purple fringing. The color accuracy is good, though most of the time the colors are a bit oversaturated.
In the Superior Auto mode the Sony Xperia Z produces photos with pleasing, albeit slightly oversaturated colors. The images shot in Normal Auto, appear more natural and lack that overprocessed look. Since most of the users will use the default Superior Auto (which usually does better anyway), we shot our samples with this mode. Either way, though, the resolved detail is hardly spectacular and noticeably lower compared to Galaxy S4's samples and the noise levels are only average. There's also noticable purple fringing and while the dynamic range is on par between the two, the Galaxy S4 has the upper hand in terms of contrast.
So even though the Sony Xperia Z produces decent shots overall, it doesn't even come close to the Galaxy S4 photos. Here go a few crops to illustrate our point.
We snapped a few photos in extreme lightning conditions. The first set of samples were taken with Auto/Normal Auto, the second pair were shot using the Night Scene presets, the third one - indoors with no additional lighting but the LED flash and the fourth - in a cloudy weather with Auto settings.
The Galaxy S4 exposes it low-light shots better than the Xperia Z's, no matter of the shooting mode. It lets in slightly more noise, but it also manages to preserve more detail and produce better colors than the Sony flagship. The Xperia Z picture quality improves though when set to shoot on Superior Auto (which automatically switch to Night Scene), in which case things are closer, but still slightly in favor of the Samsung flagship.