Commit 1605e894 authored by Martinez-Carvajal German's avatar Martinez-Carvajal German
Browse files

Adding the function for a circular region of interest

parent 68584630
......@@ -11,6 +11,52 @@ import numpy as np
from os import chdir
import pandas as pd
def sector_mask(shape,centre,radius,angle_range):
"""
CODE FROM STACK OVER FLOW
Return a boolean mask for a circular sector. The start/stop angles in
`angle_range` should be given in clockwise order.
"""
x,y = np.ogrid[:shape[0],:shape[1]]
cx,cy = centre
tmin,tmax = np.deg2rad(angle_range)
# ensure stop angle > start angle
if tmax < tmin:
tmax += 2*np.pi
# convert cartesian --> polar coordinates
r2 = (x-cx)*(x-cx) + (y-cy)*(y-cy)
theta = np.arctan2(x-cx,y-cy) - tmin
# wrap angles between 0 and 2*pi
theta %= (2*np.pi)
# circular mask
circmask = r2 <= radius*radius
# angular mask
anglemask = theta <= (tmax-tmin)
return circmask*anglemask
def ROI_circular(image, rw):
print("adjusting regions of interest ...")
# CREATING CIRCULAR MASK
# The cylinder is supposed to be the biggest "circle" inscribed in a squared image
z,x,y = np.shape(image)[0], np.shape(image)[1], np.shape(image)[2]
center = int(x/2), int(y/2)
radius = int((x/2))*rw
#Selecting circular ROI (region of interest)
mask_2D = sector_mask((x,y),center,radius,(0,360 ))
mask_3D = np.zeros(image.shape, dtype = np.bool)
for j in range(z):
mask_3D[j] = mask_2D
image[np.logical_not(mask_3D)] = 0
return image
def figure(zone, diameters_real,volume_fractions,cum_volume_fractions, path_save, file_name, bins):
# Plotting
......@@ -98,6 +144,8 @@ def main():
print('Reading pore size map ... ', file_name)
chdir(path_read)
image = tifffile.imread(file_name)
rw = 1
image = ROI_circular(image, rw)
print(image.shape)
resolution = 0.035 # mm/vox
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment