← back to Dw Photo Capture
visual-search/__pycache__/pattern_siblings.cpython-312.pyc
63 lines
�
�J�j� � �� � d Z ddlZddlZddlZddlZddlZddlZddlZddl m
Z
ddlmZm
Z
ej j dej j# d� � Z eej j dd� � Zej j d � d
k( Zej j# d� ZdZefd
�Zefd�Zd� Zd� ZddiZd� Zd� Zd� Zdd�Z dd�Z!e"dk( r�ddl#Z#e#jH dd D ]i Z% e!de%i� Z& e' ejP e&jS � D � �ci c] \ } }| dk7 s�| |�� c}} � e&d dd D �cg c] }|d |d f�� c}� �k yyc c}} w c c}w )u� Pattern-level sibling stage for visual-search (TK-12090 Lane P) — OPTIONAL, default OFF.
When a photo matches one COLORWAY, also return the other colorways of the same PATTERN.
Ported (not forked) from ~/Projects/dw-pairs-well/tools:
* signature = ci-hash-build.py dHash(8) of grayscale + dHash of the tonal inverse
* distance = pattern-id-titlefirst-final.py ci_dist: min of the 4 cross Hamming distances,
so light-on-dark and dark-on-light colorways of one motif still match
* threshold = HAM_THRESH default 30 (WS-1 value chosen 2026-06-26 in that script)
* grouping = the WS-1 title-first + CI-confirmed map pattern-id-titlefirst-by-dwsku.json
Candidate siblings come from (1) the WS-1 pattern_id group, else (2) same vendor + same normalized
pattern_name in the search index. Each candidate is then CONFIRMED by the colour-invariant distance
when both hashes are known; unhashed candidates are returned as confirmed=None (never guessed).
Env: PAIRS_WELL_TOOLS (default ~/Projects/dw-pairs-well/tools), HAM_THRESH (30),
PATTERN_SIBLINGS_FETCH=1 to hash missing images on the fly (bounded, disk-cached, $0).
� N)�defaultdict)�Image�ImageOps�PAIRS_WELL_TOOLSz~/Projects/dw-pairs-well/tools�
HAM_THRESH�30�PATTERN_SIBLINGS_FETCH�1z~/.cache/ci-hash� c �4 � | j d� j |dz |ft j � }t |j � � }d}t
|� D ]8 }||dz z }t
|� D ] }|dz |||z |||z dz kD rdndz }�" �: |d�S )N�L� r �016x)�convert�resizer �LANCZOS�list�getdata�range)�img�n�g�px�v�r�b�cs �M/Users/macstudio3/Projects/dw-photo-capture/visual-search/pattern_siblings.py�dhashr s� � ����C�����Q���
�E�M�M�:�A�
�a�i�i�k� �B��A�
�1�X��
��Q��K���q��A��a���A��E��R��A��� �]�!:�A��B�A� � � ��X�� c �^ � t t j | j d� � |� S )Nr
)r r �invertr )r r s r � inv_dhashr# '