HistoQC icon indicating copy to clipboard operation
HistoQC copied to clipboard

Add multiple colorspaces to template comparison

Open choosehappy opened this issue 6 years ago • 4 comments


Author Name: Andrew Janowczyk (@choosehappy) Original Redmine Issue: 197, http://hawking.case.edu:3000/issues/197 Original Date: 2018-05-02


not as easy as it seems, need to know each color spaces min/max value, and in the case of YUV they're not symmetric Y:[0,1] , U,V [-.5,.5]

choosehappy avatar May 21 '18 20:05 choosehappy

Hi @choosehappy I need help opening the issue link from http://hawking.case.edu:3000/issues/197.

Could you provide me with more information about this one?

nanli-emory avatar Jan 09 '23 05:01 nanli-emory

Not as informative as you'd hope :-\ here is a screenshot:

image

but i can sketch it out quickly. if you look here:

https://github.com/choosehappy/HistoQC/blob/17d81c3d93fa6465258967646eca798e694b0af3/histoqc/HistogramModule.py#L46

you'll see we always do a comparison in the RGB space

a hopefully "simple" feature is to add the ability to perform this computation in a non-RGB colorspace, e.g., YUV, HSV, etc as specified by the user

this is the relevant code from the redmine instance

def computeHistogram(img, bins, mask=-1):
    result = np.zeros(shape=(bins, 3))
    for chan in range(0, 3):
        vals = img[:, :, chan].flatten()
        if (isinstance(mask, np.ndarray)):
            vals = vals[mask.flatten()]
        result[:, chan] = np.histogram(vals, bins=bins, normed=True, range=[0, 255])[0]
    return result


def compareToTemplates(s, params):
    logging.info(f"{s['filename']} - \tcompareToTemplates")
    bins = int(params.get("bins", 20))
    limit_to_mask = strtobool(params.get("limit_to_mask", True))
    to_color_space = params.get("to_color_space", "RGB")

    img = s.getImgThumb(s["image_work_size"])

    img = convert_colorspace(img, "RGB", to_color_space)

    if (limit_to_mask):
        imghst = computeHistogram(img, bins, s["img_mask_use"])
    else:
        imghst = computeHistogram(img, bins)

    for template in params["templates"].splitlines():
        template_key = os.path.splitext(os.path.basename(template))[0]+"_"+to_color_space
        if template_key not in global_holder["templates"].keys():
            img_tmp = io.imread(template)
            img_tmp = convert_colorspace(img_tmp, "RGB", to_color_space)
            global_holder["templates"][template_key] = computeHistogram(img_tmp, bins)
        val = np.sum(pow(abs(global_holder["templates"][template_key] - imghst), 2))
        s.addToPrintList(template_key + "_MSE_hist", str(val))
    return

The question is how to figure out the right bins. since for RGB, we know the min/max values and thus can always split the [0,255] color space into evenly. in YUV, i don't know what the external values are, so its not clear how to normalize the bins

do you see what i mean?

choosehappy avatar Jan 09 '23 09:01 choosehappy

Hi @choosehappy, since we will use the image thumbnail and it should be not huge in pixels so I will use iterate each channel and find the ranges for each channel. Do you think it works?

nanli-emory avatar Jan 18 '23 14:01 nanli-emory

I don't think this will work because you will end up with different values per image, and thus the end results won't be comparable between images?

choosehappy avatar Jan 18 '23 14:01 choosehappy