thtang / CheXNet-with-localization

Weakly Supervised Learning for Findings Detection in Medical Images
https://www.csie.ntu.edu.tw/~yvchen/f106-adl/doc/HTCMedical.pdf
GNU General Public License v3.0
314 stars 108 forks source link

how to visualise the bounding_box.txt file in an image? #9

Open rajdeinno opened 5 years ago

rajdeinno commented 5 years ago

I am able to generate the bound_box.txt file after I execute the denseNet_localization.py file.

how to visualize the bound box text file into the input image? as you mentioned in ground-truth label (red) and its prediction (blue).

Thanks in advance..

Sadam1195 commented 4 years ago

@thtang does this repo has any method for that or do I have to create one for my self?

thtang commented 4 years ago

Once you have the coordinates, functions in OpenCV could deal with the bounding box visualization.

Sadam1195 commented 4 years ago
00000003_000.png 18
Atelectasis 411.8 512.5 219.0 139.1
Atelectasis 276.0 312.0 216.0 136.0
Atelectasis 524.0 308.0 216.0 136.0
Cardiomegaly 348.5 392.3 479.8 381.1
Cardiomegaly 64.0 320.0 476.0 380.0
Effusion 396.5 415.8 221.6 318.0
Effusion 656.0 96.0 220.0 316.0
Infiltration 394.5 389.1 294.0 297.4
Infiltration 104.0 100.0 292.0 296.0
Infiltration 108.0 620.0 292.0 296.0
Mass 434.3 366.7 168.7 189.8
Mass 164.0 156.0 168.0 188.0
Mass 300.0 668.0 168.0 188.0
Nodule 502.4 458.7 71.9 70.4
Nodule 64.0 732.0 68.0 68.0
Pneumonia 378.7 416.7 276.5 304.5
Pneumothorax 369.3 209.4 198.9 246.0
Pneumothorax 284.0 644.0 196.0 244.0

How do I create bounding boxes for that, can you provide an example?

Sadam1195 commented 4 years ago
import cv2
import pandas as pd
import os
import numpy

img_folder_path='/media/sadam/44C611803928605D/Downloads/ChestXray-NIHCC/a/00000003_000.png'
frame=cv2.imread(img_folder_path)

ac_bbox = '/home/sadam/CheXNet-with-localization/output/bounding_box.txt'
pd_bbox = '/home/sadam/CheXNet-with-localization/bounding_box.txt'

def plot_bbox(img_folder_path, bbox_filename):
    actual_bbox=open(bbox_filename)
    img_folder_path=os.path.split(img_folder_path)[-1]
    #print(img_folder_path)
    count=0
    temp_count=0
    final_bbox_list=[]
    for img in actual_bbox :
        if img.find(img_folder_path) != -1:
            print('file exist:',count)
            print('given image',img)
            temp_count=count
            print("this is temp count",temp_count)
        if count > temp_count:

            if img.find('/') == -1 :
                final_bbox_list.append(img)
            else:
                break
        count+=1

    i=final_bbox_list[1]
    temp_i=list(i.split(" "))
    temp_i.pop(0)

    p = numpy.array(temp_i)
    k=p.astype(float)

    x1=int(k[0])
    y1=int(k[1])
    x2=int(k[2])
    y2=int(k[3])
    return x1,y1,x2,y2

x1,y1,x2,y2=plot_bbox(img_folder_path, ac_bbox)
x_1,y_1,x_2,y_2=plot_bbox(img_folder_path, pd_bbox)

cv2.rectangle(frame,(x1,y1),(x2,y2),(0,255,0),3) #rgb 220,20,60
cv2.rectangle(frame,(x_1,y_1),(x_2,y_2),(60,20,220),3)
print(frame)
cv2.imshow('image',frame)
cv2.waitKey(0)
cv2.destroyAllWindows()

@rajdeinno I know the code is very roughly patched but it does the job. It takes an image input , checks if it's bboxes are defined in bbox actual file then draws boxed regions (predicted and actual ones). This code only draws bbox of first class of an input images. You can add further checks to work it for all class labels.

nexusorder13 commented 4 years ago

@Sadam1195 @thtang Two questions please:

a. How did you get the bounding_box.txt in output folder? Is it the ground truth? b. Why does some image have one line for a disease in output file and in some cases 3 lines for the same diseases?

Appreciate your help!

Sadam1195 commented 3 years ago

@Sadam1195 @thtang Two questions please:

a. How did you get the bounding_box.txt in output folder? Is it the ground truth? b. Why does some image have one line for a disease in output file and in some cases 3 lines for the same diseases?

Appreciate your help!

a. Bounding_box.txt has two value for each class. One value is ground truth and other is output predicted by classification model. b. If I understand your question rightly then it might be because of the output generated keeping view of the original dataset annotation. For example if original image has ground value for only one of the class then the bounding_box.txt will have two values for only one disease, one for ground truth and one for the predicted bounding_box. Maybe I can respond you better if you provide an example of your case.

Hope it helps. :) @nexusorder13

Aliktk commented 3 years ago

@Sadam1195 please how to replicate I am getting issue during replication of this study. Please help me if possible thanks

Sadam1195 commented 3 years ago

please how to replicate I am getting issue during replication of this study. Please help me if possible thanks

It is impossible to help you out without you providing any details of what kind of issue you are having. If that issue is related to this particular issue post your error here otherwise create a new issue. @Aliktk

Aliktk commented 3 years ago

@Sadam1195 thank you for your quick feedback. I know I am asking stupid question but as begginer it always be like 👍 I have an issue with the version first. I installed Pytorch==1.8.0 torchvision 0.9.0+cu111, scikit-image==0.13.1 opencv_python==3.4.0.12 numpy==1.13.3 matplotlib==2.1.1 scipy==1.0.0 sklearn==0.19.1 I have CUDA9.0, CUDA10.0 and CUDA11.0 and all other dependencies. I can shift the version of CUDA as required. I could'nt completly replicate as per your instruction in README file. I also study the technique use. I am sharing sevral question, probelm here. If I am wrong at any place please correct me please. 1- The statment given to run preprocessing file need multiple paths in the command line like DataEntry path, BB list, images path, validation and training text path, my question is all the images are in one folder?, the path include DataEntry and BB csv file names, where I should find train and val text file in your study? 2- This study is old but it can be replicated? 3- I have IBM inctance but here this study based on linux OS should it be possible on window based? Thanks you so much for your help. In futur can I contact you for guidanceabout this project?

Aliktk commented 3 years ago

@Sadam1195 @thtang
I have done image preprocessing. Now I want to train the network but as the memory dumped in preprocessing but still, I have been done it. In training, the system hanged and RAM memory is full, I have 64GB ram with 50GB+ paging (virtual ram). Do you have any idea how to tackle this error?

Sadam1195 commented 3 years ago

@Sadam1195 @thtang I have done image preprocessing. Now I want to train the network but as the memory dumped in preprocessing but still, I have been done it. In training, the system hanged and RAM memory is full, I have 64GB ram with 50GB+ paging (virtual ram). Do you have any idea how to tackle this error?

You probably have low GPU memory. Try Colab or Kaggle Kernels. Please do not tag me, this is not facebook. If you face any issues create a new issue and comment your problem along with the error you are getting. Hope it helps.