Esempio n. 1
0
def process_xray_image(crt_xray_image, DenseNetImageNet121_model):

    #     print(crt_xray_image.shape)
    crt_xray_image = azure_chestxray_utils.normalize_nd_array(crt_xray_image)
    crt_xray_image = 255 * crt_xray_image
    crt_xray_image = crt_xray_image.astype('uint8')

    crt_predictions, crt_cam_image, predicted_disease_index = get_score_and_cam_picture(
        crt_xray_image, DenseNetImageNet121_model)

    prj_consts = azure_chestxray_utils.chestxray_consts()
    likely_disease = prj_consts.DISEASE_list[predicted_disease_index]
    likely_disease_prob = 100 * crt_predictions[predicted_disease_index]
    likely_disease_prob_ratio = 100 * crt_predictions[
        predicted_disease_index] / sum(crt_predictions)
    print('predictions: ', crt_predictions)
    print('likely disease: ', likely_disease)
    print('likely disease prob: ', likely_disease_prob)
    print('likely disease prob ratio: ', likely_disease_prob_ratio)

    crt_blended_image = process_cam_image(crt_cam_image, crt_xray_image)
    plot_cam_results(
        crt_blended_image, crt_cam_image, crt_xray_image,
        str(likely_disease) + ' ' + "{0:.1f}".format(likely_disease_prob) +
        '% (weight ' + "{0:.1f}".format(likely_disease_prob_ratio) + '%)')
def get_image_score_and_serialized_cam(crt_cv2_image, crt_chest_XRay_model):
    prj_consts = azure_chestxray_utils.chestxray_consts()
    crt_cv2_image = azure_chestxray_utils.normalize_nd_array(crt_cv2_image)
    crt_cv2_image = 255*crt_cv2_image
    crt_cv2_image=crt_cv2_image.astype('uint8')
    predictions, cam_image, predicted_disease_index = \
    azure_chestxray_cam.get_score_and_cam_picture(crt_cv2_image, crt_chest_XRay_model)
    blended_image = azure_chestxray_cam.process_cam_image(cam_image, crt_cv2_image)
    serialized_image = azure_chestxray_cam.plot_cam_results(blended_image, cam_image, crt_cv2_image, \
                 prj_consts.DISEASE_list[predicted_disease_index])
    return predictions, serialized_image
Esempio n. 3
0
def process_nih_data(nih_data_files, NIH_data_dir, DenseNetImageNet121_model):
    for crt_image in nih_data_files:
        # print(crt_image)
        prj_consts = azure_chestxray_utils.chestxray_consts()

        crt_xray_image = cv2.imread(os.path.join(NIH_data_dir,crt_image))
        crt_xray_image = cv2.resize(crt_xray_image, 
                                    (prj_consts.CHESTXRAY_MODEL_EXPECTED_IMAGE_HEIGHT, 
                                     prj_consts.CHESTXRAY_MODEL_EXPECTED_IMAGE_WIDTH)) \
                        .astype(np.float32)

        process_xray_image(crt_xray_image, DenseNetImageNet121_model )   
Esempio n. 4
0
                 np.float32)

        process_xray_image(crt_xray_image, DenseNetImageNet121_model)


if __name__ == "__main__":
    #FIXME
    # add example/test code here

    NIH_annotated_Cardiomegaly = ['00005066_030.png']
    data_dir = ''
    cv2_image = cv2.imread(
        os.path.join(data_dir, NIH_annotated_Cardiomegaly[0]))

    azure_chestxray_utils.print_image_stats_by_channel(cv2_image)
    cv2_image = azure_chestxray_utils.normalize_nd_array(cv2_image)
    cv2_image = 255 * cv2_image
    cv2_image = cv2_image.astype('uint8')
    azure_chestxray_utils.print_image_stats_by_channel(cv2_image)

    predictions, cam_image, predicted_disease_index = get_score_and_cam_picture(
        cv2_image, model)
    print(predictions)
    prj_consts = azure_chestxray_utils.chestxray_consts()
    print(prj_consts.DISEASE_list[predicted_disease_index])
    print('likely disease: ', prj_consts.DISEASE_list[predicted_disease_index])
    print('likely disease prob ratio: ',
          predictions[predicted_disease_index] / sum(predictions))
    blended_image = process_cam_image(cam_image, cv2_image)
    plot_cam_results(blended_image, cam_image, cv2_image,
                     prj_consts.DISEASE_list[predicted_disease_index])