MCPcopy Index your code
hub / github.com/thygate/stable-diffusion-webui-depthmap-script / ImageandPatchs

Class ImageandPatchs

src/depthmap_generation.py:562–660  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

560
561
562class ImageandPatchs:
563 def __init__(self, root_dir, name, patchsinfo, rgb_image, scale=1):
564 self.root_dir = root_dir
565 self.patchsinfo = patchsinfo
566 self.name = name
567 self.patchs = patchsinfo
568 self.scale = scale
569
570 self.rgb_image = cv2.resize(rgb_image, (round(rgb_image.shape[1] * scale), round(rgb_image.shape[0] * scale)),
571 interpolation=cv2.INTER_CUBIC)
572
573 self.do_have_estimate = False
574 self.estimation_updated_image = None
575 self.estimation_base_image = None
576
577 def __len__(self):
578 return len(self.patchs)
579
580 def set_base_estimate(self, est):
581 self.estimation_base_image = est
582 if self.estimation_updated_image is not None:
583 self.do_have_estimate = True
584
585 def set_updated_estimate(self, est):
586 self.estimation_updated_image = est
587 if self.estimation_base_image is not None:
588 self.do_have_estimate = True
589
590 def __getitem__(self, index):
591 patch_id = int(self.patchs[index][0])
592 rect = np.array(self.patchs[index][1]['rect'])
593 msize = self.patchs[index][1]['size']
594
595 ## applying scale to rect:
596 rect = np.round(rect * self.scale)
597 rect = rect.astype('int')
598 msize = round(msize * self.scale)
599
600 patch_rgb = impatch(self.rgb_image, rect)
601 if self.do_have_estimate:
602 patch_whole_estimate_base = impatch(self.estimation_base_image, rect)
603 patch_whole_estimate_updated = impatch(self.estimation_updated_image, rect)
604 return {'patch_rgb': patch_rgb, 'patch_whole_estimate_base': patch_whole_estimate_base,
605 'patch_whole_estimate_updated': patch_whole_estimate_updated, 'rect': rect,
606 'size': msize, 'id': patch_id}
607 else:
608 return {'patch_rgb': patch_rgb, 'rect': rect, 'size': msize, 'id': patch_id}
609
610 def print_options(self, opt):
611 """Print and save options
612
613 It will print both current options and default values(if different).
614 It will save options into a text file / [checkpoints_dir] / opt.txt
615 """
616 message = ''
617 message += '----------------- Options ---------------\n'
618 for k, v in sorted(vars(opt).items()):
619 comment = ''

Callers 1

estimateboostFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected