Skip to content

datasets

create_dummy_row(size, output_filename)

Function to create a dummy row with path to an image and seed point corresponding to the image

Source code in fmcib/datasets/__init__.py
def create_dummy_row(size, output_filename):
    """
    Function to create a dummy row with path to an image and seed point corresponding to the image
    """

    # Create a np array initialized with random values between -1024 and 2048
    np_image = np.random.randint(-1024, 2048, size, dtype=np.int16)

    # Create an itk image from the numpy array
    itk_image = sitk.GetImageFromArray(np_image)

    # Save itk image to file with the given output filename
    sitk.WriteImage(itk_image, output_filename)

    x, y, z = generate_random_seed_point(itk_image.GetSize())

    # Convert to global coordinates
    x, y, z = itk_image.TransformContinuousIndexToPhysicalPoint((x, y, z))

    return {
        "image_path": output_filename,
        "PatientID": random.randint(0, 100000),
        "coordX": x,
        "coordY": y,
        "coordZ": z,
        "label": random.randint(0, 1),
    }

generate_random_seed_point(image_size)

Function to generate a random x, y, z coordinate within the image

Source code in fmcib/datasets/__init__.py
def generate_random_seed_point(image_size):
    """
    Function to generate a random x, y, z coordinate within the image
    """
    x = random.randint(0, image_size[0] - 1)
    y = random.randint(0, image_size[1] - 1)
    z = random.randint(0, image_size[2] - 1)

    return (x, y, z)