def convertTo8bits(currentSlice, npArrayMin, npArrayMax):
    """
    Description: Converts the given slice into a 8-bit array
    Params:
        - currentSlice: 2D slice
        - npArrayMin: the minimum voxel value of the entire volume
        - npArrayMax: the maximum voxel value of the entire volume
    Returns:
        - Converted image
    """

    # Normalize pixel values
    currentSlice = (currentSlice - npArrayMin) * 255.0 / (npArrayMax - npArrayMin)

    # Convert to 8 bits (required to export as PNG)
    currentSlice = (currentSlice).astype('uint8')

    return currentSlice