<commit_before># -*- coding: utf-8 -*-
"""
-------------------------------------------------------------------------------
Purpose:     (CZE-ZCU-FAV-KKY) Liver medical project

Author:      <NAME>
Email:       <EMAIL>

Created:     2014/02/22
Copyright:   (c) <NAME>
-------------------------------------------------------------------------------
"""

import numpy
import scipy
import scipy.ndimage
from scipy import stats

import matplotlib
import matplotlib.pyplot as matpyplot

def prepareVisualization(data):

    img0 = numpy.sum(data, axis = 0)
    img0[img0 > 0] += numpy.max(img0)

    img1 = numpy.sum(data, axis = 1)
    img1[img1 > 0] += numpy.max(img1)

    img2 = numpy.sum(data, axis = 2)
    img2[img2 > 0] += numpy.max(img2)

    return img0, img1, img2

def gaussFilter(data, sigma):

        """

        Aplikace gaussova filtru.

        """

        ## Filtrovani
        scipy.ndimage.filters.gaussian_filter(data, sigma, order = 0, output = data, mode = 'nearest')

        return data
        
def thresholding(data, min_threshold, max_threshold, use_min_threshold = True, use_max_Threshold = True):

        """

        Prahovani podle minimalniho a maximalniho prahu.

        """

        if use_min_threshold:
            
            data = data * (data >= min_threshold)

        if use_max_Threshold:

            data = data * (data <= max_threshold)

        return data

def binaryClosingOpening(data, closeNum, openNum, firstClosing = True):

        """

        Aplikace binarniho uzavreni a pote binarniho otevreni.

        """

        numpyDataOnes = numpy.ones(data.shape, dtype = type(data[0][0][0]))

        if firstClosing:

            ## Vlastni binarni uzavreni.
            if (closeNum >= 1):

                data = data * scipy.ndimage.binary_closing(data, iterations = closeNum)

            ## Vlastni binarni otevreni.
            if (openNum >= 1):

                data = data * scipy.ndimage.binary_opening(data, iterations = openNum)

        else:          

            ## Vlastni binarni otevreni.
            if (openNum >= 1):

                data = data * scipy.ndimage.binary_opening(data, iterations = openNum)

            ## Vlastni binarni uzavreni.
            if (closeNum >= 1):

                data = data * scipy.ndimage.binary_closing(data, iterations = closeNum)

        return data

def calculateSigma(voxel, input):

        """

        Spocita novou hodnotu sigma pro gaussovo filtr.

        """

        voxelV = voxel[0] * voxel[1] * voxel[2]

        if (voxel[0] == voxel[1] == voxel[2]):

            return ((5 / voxel[0]) * input) / voxelV

        else:
<commit_msg>closing operation border error fix<commit_after># -*- coding: utf-8 -*-
"""
-------------------------------------------------------------------------------
Purpose:     (CZE-ZCU-FAV-KKY) Liver medical project

Author:      <NAME>
Email:       <EMAIL>

Created:     2014/02/22
Copyright:   (c) <NAME>
-------------------------------------------------------------------------------
"""

import logging
logger = logging.getLogger(__name__)

import numpy
import scipy
import scipy.ndimage
from scipy import stats

import matplotlib
import matplotlib.pyplot as matpyplot

def prepareVisualization(data):

    img0 = numpy.sum(data, axis = 0)
    img0[img0 > 0] += numpy.max(img0)

    img1 = numpy.sum(data, axis = 1)
    img1[img1 > 0] += numpy.max(img1)

    img2 = numpy.sum(data, axis = 2)
    img2[img2 > 0] += numpy.max(img2)

    return img0, img1, img2

def gaussFilter(data, sigma):

        """

        Aplikace gaussova filtru.

        """

        ## Filtrovani
        scipy.ndimage.filters.gaussian_filter(data, sigma, order = 0, output = data, mode = 'nearest')

        return data
        
def thresholding(data, min_threshold, max_threshold, use_min_threshold = True, use_max_Threshold = True):

        """

        Prahovani podle minimalniho a maximalniho prahu.

        """

        if use_min_threshold:
            
            data = data * (data >= min_threshold)

        if use_max_Threshold:

            data = data * (data <= max_threshold)

        return data

def binaryClosingOpening(data, closeNum, openNum, firstClosing = True, fixBorder = True):

        """

        Aplikace binarniho uzavreni a pote binarniho otevreni.

        """
        
        # This creates empty border around data, so closing operations wont cut off parts of segmented data on the sides
        if fixBorder and closeNum>=1:
            shape = data.shape
            new_shape = (shape[0]+closeNum*2,
                         shape[1]+closeNum*2, 
                         shape[2]+closeNum*2)
            logger.debug('Creating empty border for closeing operation...')
            logger.debug('orig shape: '+str(shape)+' new shape: '+str(new_shape))
            
            new_data = numpy.zeros(new_shape, dtype = type(data[0][0][0]))
            new_data[closeNum:closeNum+shape[0],
                     closeNum:closeNum+shape[1],
                     closeNum:closeNum+shape[2]] = data
            data = new_data
            del(new_data)
        
        # @TODO - not used!!!, why was this here?
        #numpyDataOnes = numpy.ones(data.shape, dtype = type(data[0][0][0]))

        if firstClosing:

            ## Vlastni binarni uzavreni.
            if (closeNum >= 1):

                data = data * scipy.ndimage.binary_closing(data, iterations = closeNum)

            ## Vlastni binarni otevreni.
            if (openNum >= 1):

                data = data * scipy.ndimage.binary_opening(data, iterations = openNum)

        else:          

            ## Vlastni binarni otevreni.
            if (openNum >= 1):

                data = data * scipy.ndimage.binary_opening(data, iterations = openNum)

            ## Vlastni binarni uzavreni.
            if (closeNum >= 1):

                data = data * scipy.ndimage.binary_closing(data, iterations = closeNum)
                
        # Removes added empty border. Returns data matrix to original size.
        if fixBorder and closeNum>=1:
            data = data[closeNum:closeNum+shape[0],
                        closeNum:closeNum+shape[1],
                        closeNum:closeNum+shape[2]]

        return data

def calculateSigma(voxel, input):

        """

        Spocita novou hodnotu sigma pro gaussovo filtr.

        """

        voxelV = voxel[0] * voxel[1] * voxel[2]

        if (voxel[0] == voxel[1] == voxel[2]):

            return ((5 / voxel[0]) * input) / voxelV

        else:

{'fraction_non_alphanumeric': 0.15262515262515264, 'fraction_numerical': 0.016636141636141636, 'mean_word_length': 1.7067327550598925, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4985810', 'n_tokens_mistral': 2126, 'n_tokens_neox': 1950, 'n_words': 477}