Skip to content
Snippets Groups Projects
Commit 17b427ef authored by Pietro Incardona's avatar Pietro Incardona
Browse files

Adding example files

parent f5694daf
No related branches found
No related tags found
No related merge requests found
Pipeline #2281 passed
%% Cell type:code id: tags:
``` python
from tifffile import imread, imsave
import numpy as np
import os
import matplotlib.pyplot as plt
import cv2
import sys
sys.path.append("./lib")
import morphological_operations as mo
import image_process_and_save as ips
```
%% Cell type:markdown id: tags:
# Open and plot image
%% Cell type:code id: tags:
``` python
filename = '/Users/jstark/Desktop/image_examples/face.tiff'
x = imread('%s' % filename)
x = x[:, :, 0]
```
%% Cell type:code id: tags:
``` python
np.max(x), np.min(x), x.shape
```
%% Output
(255, 0, (64, 58))
%% Cell type:code id: tags:
``` python
# fig, ax = plt.subplots(figsize=(7, 7))
# ax.imshow(x, cmap='gray')
```
%% Cell type:markdown id: tags:
# Convert binary image: >1 -> -1, 0 -> +1 (indicator function)
%% Cell type:code id: tags:
``` python
x_bin = np.where(x > 1, -1, 1)
print("format of stack x_bin = ", x_bin.shape, "\n"),
print("minimum pixel value after conversion = ", np.amin(x_bin), "\n"),
print("maximum pixel value after conversion = ", np.amax(x_bin), "\n")
# fig, ax = plt.subplots(figsize=(7, 7))
# ax.imshow(x_bin[30], cmap = 'gray')
fig, ax = plt.subplots(figsize=(7, 7))
ax.imshow(x_bin, cmap='gray')
None
```
%% Output
format of stack x_bin = (64, 58)
minimum pixel value after conversion = -1
maximum pixel value after conversion = 1
%% Cell type:code id: tags:
``` python
np.min(x_bin), np.max(x_bin)
```
%% Output
(-1, 1)
%% Cell type:code id: tags:
``` python
x_bin = np.flip(x_bin)
fig, ax = plt.subplots(figsize=(7, 7))
ax.imshow(x_bin, cmap='gray')
None
```
%% Output
%% Cell type:code id: tags:
``` python
# save flat image stack as binary file
path = '/Users/jstark/Desktop/image_examples/'
filename = 'face'
ips.save_array_toBin(x_bin, path, filename)
# Save image size in #pixels / axis as csv file
dim = np.asarray(x_bin.shape)
np.savetxt('%s/size_%s.csv' % (path, filename), dim, fmt='%i', delimiter=',')
```
import os
import numpy as np
def padding(img, x_pad, y_pad, z_pad):
z, y, x = img.shape[0], img.shape[1], img.shape[2]
zp, yp, xp = z + 2*z_pad, y + 2*y_pad, x + 2*x_pad
x_padded = np.zeros((zp, yp, xp ))
x_padded[z_pad:zp-z_pad, y_pad:yp-y_pad, x_pad:xp-x_pad] = img
return x_padded
def save_zslices_toBin(numpy_array, filename):
import os
curdir = os.getcwd()
directory = '%s/%s'% (curdir, filename)
if not os.path.exists(directory):
os.makedirs(directory)
# loop through z dim and save every slice as separate binary file bc. savetxt only works for 1d or 2d arrays
z_dim = numpy_array.shape[0]
for z in range(z_dim):
numpy_array[z].astype('int8').tofile('%s/zslice_%d.bin' % (directory, z))
def save_array_toBin(numpy_array, path, filename):
if not os.path.exists(path):
os.makedirs(path)
numpy_array.astype('int8').tofile('%s/%s.bin' % (path, filename))
import cv2
import numpy as np
def closure(img, kernel, iterations):
lz, ly, lx = img.shape[0], img.shape[1], img.shape[2]
erosion = np.zeros((lz, ly, lx))
dilation = np.zeros((lz, ly, lx))
# Closure
# -> connects separated regions, increase connectivity
i = 0
while i < 1:
for z_slice in range(lz):
dilation[z_slice] = cv2.dilate(img[z_slice], kernel, iterations = iterations)
img = dilation
for z_slice in range(lz):
erosion[z_slice] = cv2.erode(img[z_slice], kernel, iterations = iterations)
img = erosion
i += 1;
return img
def opening(img, kernel, iterations):
lz, ly, lx = img.shape[0], img.shape[1], img.shape[2]
erosion = np.zeros((lz, ly, lx))
dilation = np.zeros((lz, ly, lx))
# Opening
# -> removes islands / small regions
i = 0
while i < 1:
for z_slice in range(lz):
erosion[z_slice] = cv2.erode(img[z_slice], kernel, iterations = iterations)
img = erosion
for z_slice in range(lz):
dilation[z_slice] = cv2.dilate(img[z_slice], kernel, iterations = iterations)
img = dilation
i += 1;
return img
\ No newline at end of file
......@@ -414,11 +414,11 @@ fi
echo "INCLUDE_PATH=$cuda_include_dirs -Wno-deprecated-declarations $openmp_flags -I. -I$install_base/openfpm_numerics/include -I$install_base/openfpm_pdata/include/config -I$install_base/openfpm_pdata/include -I$install_base/openfpm_data/include -I$install_base/openfpm_vcluster/include -I$install_base/openfpm_io/include -I$install_base/openfpm_devices/include -I$i_dir/VCDEVEL/include -I$i_dir/METIS/include -I$i_dir/PARMETIS/include -I$i_dir/BOOST/include -I$i_dir/HDF5/include -I$i_dir/LIBHILBERT/include $lin_alg_inc" > example.mk
echo "LIBS_PATH=$openmp_flags -L$install_base/openfpm_devices/lib -L$install_base/openfpm_pdata/lib -L$install_base/openfpm_vcluster/lib -L$i_dir/VCDEVEL/lib -L$i_dir/METIS/lib -L$i_dir/PARMETIS/lib -L$i_dir/BOOST/lib -L$hdf5_lib -L$i_dir/LIBHILBERT/lib $lin_alg_dir " >> example.mk
if [ x"$gpu_support" == x"1" ]; then
echo "LIBS=-lvcluster -lofpm_pdata -lofpmmemory -lparmetis -lmetis -lboost_iostreams -lboost_program_options -lhdf5 -llibhilbert -lVc $(cat cuda_lib) $lin_alg_lib -ldl" >> example.mk
echo "LIBS_SE2=-lvcluster -lofpmmemory_se2 -lparmetis -lmetis -lboost_iostreams -lboost_program_options -lhdf5 -llibhilbert -lVc $(cat cuda_lib) $lin_alg_lib" >> example.mk
echo "LIBS=-lvcluster -lofpm_pdata -lofpmmemory -lparmetis -lmetis -lboost_iostreams -lboost_program_options -lhdf5 -llibhilbert -lVc $(cat cuda_lib) $lin_alg_lib -ldl -lboost_filesystem -lboost_system" >> example.mk
echo "LIBS_SE2=-lvcluster -lofpmmemory_se2 -lparmetis -lmetis -lboost_iostreams -lboost_program_options -lhdf5 -llibhilbert -lVc $(cat cuda_lib) $lin_alg_lib -lboost_filesystem -lboost_system" >> example.mk
else
echo "LIBS=-lvcluster -lofpm_pdata -lofpmmemory -lparmetis -lmetis -lboost_iostreams -lboost_program_options -lhdf5 -llibhilbert -lVc $lin_alg_lib -ldl" >> example.mk
echo "LIBS_SE2=-lvcluster -lofpmmemory_se2 -lparmetis -lmetis -lboost_iostreams -lboost_program_options -lhdf5 -llibhilbert -lVc $lin_alg_lib" >> example.mk
echo "LIBS=-lvcluster -lofpm_pdata -lofpmmemory -lparmetis -lmetis -lboost_iostreams -lboost_program_options -lhdf5 -llibhilbert -lVc $lin_alg_lib -ldl -lboost_filesystem -lboost_system" >> example.mk
echo "LIBS_SE2=-lvcluster -lofpmmemory_se2 -lparmetis -lmetis -lboost_iostreams -lboost_program_options -lhdf5 -llibhilbert -lVc $lin_alg_lib -lboost_filesystem -lboost_system" >> example.mk
fi
echo "INCLUDE_PATH_NVCC=-Xcompiler="-Wno-deprecated-declarations" $(cat openmp_flags) "$(cat cuda_options)" -I. -I$install_base/openfpm_numerics/include -I$install_base/openfpm_pdata/include/config -I$install_base/openfpm_pdata/include -I$install_base/openfpm_data/include -I$install_base/openfpm_vcluster/include -I$install_base/openfpm_io/include -I$install_base/openfpm_devices/include -I$i_dir/METIS/include -I$i_dir/PARMETIS/include -I$i_dir/BOOST/include -I$i_dir/HDF5/include -I$i_dir/LIBHILBERT/include $lin_alg_inc" >> example.mk
cp example.mk src/example.mk
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment