如何用Python检测3D图像是HSBS还是OU格式?
Nice work getting to the disparity map stage—you’re already ahead of the game! Here’s how to leverage that existing skill to tell apart horizontal side-by-side (HSBS) and over-under (OU) 3D formats:
Split the image into both possible stereo pairs
First, generate the two candidate eye pairs based on the two common formats:- For HSBS: Slice the image vertically into left (
image_width // 2x image_height) and right halves - For OU: Slice the image horizontally into top (image_width x
image_height // 2) and bottom halves
Pro tip: If your image has odd dimensions, round down to the nearest even number for each split to keep the two halves perfectly sized.
- For HSBS: Slice the image vertically into left (
Run your disparity calculation on both pairs
Use your existing disparity map algorithm on both the left-right (HSBS candidate) and top-bottom (OU candidate) pairs.Compare the disparity results to find the valid format
The core idea is that a genuine stereo pair will produce a coherent, meaningful disparity map, while the incorrect split will result in almost no consistent disparity:- Calculate the average absolute disparity value for each map. The pair with the noticeably higher average is the correct format.
- For more accuracy, check disparity coherence: Valid stereo maps will have regions of consistent shift (e.g., foreground objects showing a clear disparity relative to background), while the invalid pair’s map will look random or have near-zero values across most of the frame.
- If dealing with low-disparity scenes (like wide landscapes), fall back to checking pixel correlation between the two halves—valid stereo pairs will have high correlation in corresponding areas, while mismatched splits won’t.
内容的提问来源于stack exchange,提问作者Terence Eden

