def calibrate(self, pixel_cm_ratio, tr): self.pixelcmratio = "{0:.2f}".format(pixel_cm_ratio) self.rgbtransform = ",".join(["{0:.2f}".format(x) for x in tr.flatten()]) self.correctedlength = "{0:.2f}".format(self.length / pixel_cm_ratio) self.correctedwidth = "{0:.2f}".format(self.width / pixel_cm_ratio) correctedrgb = np.dot(tr, np.array(self.rgb)) self.correctedrgb = triplet_to_rgb(correctedrgb) self.correctedcolorname = closest_color(correctedrgb) self.calibrated = True
def __init__(self, imagename, accession, seedno, rgb, props, exif): self.imagename = imagename self.accession = accession self.seedno = seedno y, x = props.centroid self.x, self.y = int(round(x)), int(round(y)) self.location = "{0}|{1}".format(self.x, self.y) self.area = int(round(props.area)) self.length = int(round(props.major_axis_length)) self.width = int(round(props.minor_axis_length)) self.props = props self.circularity = 4 * pi * props.area / props.perimeter ** 2 self.rgb = rgb self.colorname = closest_color(rgb) self.datetime = exif.get("exif:DateTimeOriginal", "none") self.rgbtag = triplet_to_rgb(rgb) self.pixeltag = "length={0} width={1} area={2}".format(self.length, self.width, self.area) self.hashtag = " ".join((self.rgbtag, self.colorname)) self.calibrated = False
def __init__(self, imagename, accession, seedno, rgb, props, exif): self.imagename = imagename self.accession = accession self.seedno = seedno y, x = props.centroid self.x, self.y = int(round(x)), int(round(y)) self.location = "{0}|{1}".format(self.x, self.y) self.area = int(round(props.area)) self.length = int(round(props.major_axis_length)) self.width = int(round(props.minor_axis_length)) self.props = props self.circularity = 4 * pi * props.area / props.perimeter**2 self.rgb = rgb self.colorname = closest_color(rgb) self.datetime = exif.get("exif:DateTimeOriginal", "none") self.rgbtag = triplet_to_rgb(rgb) self.pixeltag = "length={0} width={1} area={2}".format( self.length, self.width, self.area) self.hashtag = " ".join((self.rgbtag, self.colorname)) self.calibrated = False
def test_closest_color(input, output): from jcvi.utils.webcolors import closest_color assert closest_color(input) == output