"""Fixed image-only prompt subsets from a 16x16 grid of image positions."""
import numpy as np

def sample_64(gray,points):
 """Return uniform, contrast-stratified and mixed indices.

 Contrast is local standard deviation in a 32x32 window. Four points are
 chosen from each 128x128 cell; the mixed rule uses a 32-point uniform
 checkerboard followed by 32 contrast-ranked points balanced by cell.
 """
 gray=np.asarray(gray);points=np.asarray(points)
 if gray.shape!=(512,512) or gray.dtype!=np.uint8 or points.shape!=(256,2):raise ValueError('Expected 512 grayscale image and 256 points')
 expected=np.array([(x,y) for y in range(16,512,32) for x in range(16,512,32)])
 if not np.array_equal(points,expected):raise ValueError('Expected ordered 32-pixel grid')
 std=np.array([float(np.std(gray[y-16:y+16,x-16:x+16],dtype=np.float64)) for x,y in points]);groups=[]
 for cy in range(4):
  for cx in range(4):
   idx=[i for i,(x,y) in enumerate(points) if x//128==cx and y//128==cy];groups.append(sorted(idx,key=lambda i:(-std[i],i)))
 uniform=[i for i in range(256) if (i%16)%2==0 and (i//16)%2==0]
 contrast=[g[j] for j in range(4) for g in groups]
 checker=[i for i in uniform if ((i%16)//2+(i//16)//2)%2==0]
 mixed=checker.copy();seen=set(mixed)
 for j in range(16):
  for group in groups:
   i=group[j]
   if i not in seen and len(mixed)<64:mixed.append(i);seen.add(i)
 if not all(len(s)==len(set(s))==64 for s in (uniform,contrast,mixed)):raise AssertionError('Unexpected prompt counts')
 return {'uniform':uniform,'contrast':contrast,'mixed':mixed},std
