Draw discovered similar image regions.
(image, clust, size)
| 183 | return clusters |
| 184 | |
| 185 | def marksimilar(image, clust, size): |
| 186 | """ |
| 187 | Draw discovered similar image regions. |
| 188 | """ |
| 189 | global opt |
| 190 | blocks = [] |
| 191 | if clust: |
| 192 | draw = ImageDraw.Draw(image) |
| 193 | mask = Image.new('RGB', (size,size), 'cyan') |
| 194 | for cl in clust: |
| 195 | for x,y in cl: |
| 196 | im = image.crop((x,y,x+size,y+size)) |
| 197 | im = Image.blend(im,mask,0.5) |
| 198 | blocks.append((x,y,im)) |
| 199 | for bl in blocks: |
| 200 | x,y,im = bl |
| 201 | image.paste(im,(x,y,x+size,y+size)) |
| 202 | if int(opt.imauto): |
| 203 | for cl in clust: |
| 204 | cx1 = min([cx for cx,cy in cl]) |
| 205 | cy1 = min([cy for cx,cy in cl]) |
| 206 | cx2 = max([cx for cx,cy in cl]) + block_len |
| 207 | cy2 = max([cy for cx,cy in cl]) + block_len |
| 208 | draw.rectangle([cx1,cy1,cx2,cy2],outline="magenta") |
| 209 | return image |
| 210 | |
| 211 | if __name__ == '__main__': |
| 212 | cmd = OptionParser("usage: %prog image_file [options]") |