Python skimage.exposure.equalize_adapthist() Examples

The following are 9 code examples of skimage.exposure.equalize_adapthist(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module skimage.exposure , or try the search function .
Example #1
Source File: utilityFunctions.py    From DICOM-CNN with MIT License 6 votes vote down vote up
def readScan(scanNum, dirName):
    """ Reads a DICOM file from a directory

    Given a directory name and the number of the file containing the image to be read, reads in and returns a numpy representation of the image. Also normalizes the pixel values of the image.

    Args:
        scanNum: An integer containing the one-based index of the file to be read
        dirName: A string representation of the name of the directory to be opened. This directory should be a child of the working directory. Ex: "trainingImages"

    Returns: 
        A numpy array containing the pixel data for the image
    """

    for root, dir, files in os.walk("./" + dirName):
        scans = [file  for file in files if file != "desktop.ini"]
        print("Reading image " + scans[scanNum] + " from " + dirName)
        data = numpy.load("./" + dirName + "/" + scans[scanNum])
        #plt.imshow(data)
        #plt.show()
        data = exposure.equalize_adapthist(data)        
        #plt.imshow(data)
        #plt.show()
        return data
    print(dirName + " is not a valid directory")
    exit(-1) 
Example #2
Source File: TrainClassifierEnsemble.py    From kaggle-rsna18 with MIT License 5 votes vote down vote up
def apply_clahe(img): 
    img = img / 255. 
    img = exposure.equalize_adapthist(img) 
    img = img * 255. 
    return img 

# == AUGMENTATION == # 
Example #3
Source File: TrainOneClassifier.py    From kaggle-rsna18 with MIT License 5 votes vote down vote up
def apply_clahe(img): 
    img = img / 255. 
    img = exposure.equalize_adapthist(img) 
    img = img * 255. 
    return img 

# == AUGMENTATION == # 
Example #4
Source File: utilityFunctions.py    From DICOM-CNN with MIT License 5 votes vote down vote up
def normReadAll():
    """ Reads all images in the training set

    Reads all images from the training set. Assumes that the working directory has subdirectories "PosTrain" and "NegTrain"

    Returns:
        A numpy array containing the pixel values for the batch of images. Also returns a numpy array containing whether each image has a positive or negative label
    """
    
    labels = []
    patientData = []
    
    posLen = imageCount("PosTrain")
    negLen = imageCount("NegTrain")

    for i in range(posLen):
        data = readScan(i, "PosTrain")
        labels.append(1)
        data = exposure.equalize_adapthist(data)        
        patientData.append(data)
    for i in range(negLen):
        data = readScan(i, "NegTrain")
        labels.append(0)
        data = exposure.equalize_adapthist(data)        
        patientData.append(data)
    
    patientData = numpy.stack(patientData).astype(float)
    return patientData, numpy.stack(labels) 
Example #5
Source File: utilityFunctions.py    From DICOM-CNN with MIT License 5 votes vote down vote up
def readTest():
    """ Reads all images in the test set

    Reads all images from the test set. Assumes that the working directory has subdirectories "PosTest" and "NegTest"

    Returns:
        A numpy array containing the pixel values for the batch of images. Also returns a numpy array containing whether each image has a positive or negative label
    """
    labels = []
    patientData = []
    
    posLen = imageCount("PosTest")
    negLen = imageCount("NegTest")

    for i in range(posLen):
        data = readScan(i, "PosTest")
        labels.append(1)
        data = exposure.equalize_adapthist(data)        
        patientData.append(data)
    for i in range(negLen):
        data = readScan(i, "NegTest")
        labels.append(0)
        data = exposure.equalize_adapthist(data)        
        patientData.append(data)
    
    patientData = numpy.stack(patientData).astype(float)
    return patientData, numpy.stack(labels) 
Example #6
Source File: predict-checkpoint.py    From cvpr-2018-autonomous-driving-autopilot-solution with MIT License 5 votes vote down vote up
def crop_and_resize_test(image, contrast = False):
    img_crop = np.zeros([image_size[0], image_size[1], 3], dtype = np.float)
    img_roi = image[-image_size[0]:, :, :]
    if contrast:
        img_adapteq = exposure.equalize_adapthist(img_roi, clip_limit=0.01)
    else:
        img_adapteq = img_roi / 255.0
    img_adapteq = img_adapteq * 255.0
    img_crop[:, 72:(72+3384), :] = img_adapteq
    return img_crop 
Example #7
Source File: predict.py    From cvpr-2018-autonomous-driving-autopilot-solution with MIT License 5 votes vote down vote up
def crop_and_resize_test(image, contrast = False):
    img_crop = np.zeros([image_size[0], image_size[1], 3], dtype = np.float)
    img_roi = image[-image_size[0]:, :, :]
    if contrast:
        img_adapteq = exposure.equalize_adapthist(img_roi, clip_limit=0.01)
    else:
        img_adapteq = img_roi / 255.0
    img_adapteq = img_adapteq * 255.0
    img_crop[:, 72:(72+3384), :] = img_adapteq
    return img_crop 
Example #8
Source File: tf_eval.py    From 3d-dl with MIT License 5 votes vote down vote up
def adaptive_equalize(img):
    # Adaptive Equalization
    img = img_as_float(img)
    img_adapteq = exposure.equalize_adapthist(img, clip_limit=0.05)
    return img_as_ubyte(img_adapteq) 
Example #9
Source File: test.py    From 3d-dl with MIT License 5 votes vote down vote up
def adaptive_equalize(img):
    # Adaptive Equalization
    img = img_as_float(img)
    img_adapteq = exposure.equalize_adapthist(img, clip_limit=0.05)
    return img_as_ubyte(img_adapteq)