Skip to content

Commit

Permalink
img order
Browse files Browse the repository at this point in the history
  • Loading branch information
ggruszczynski committed Apr 25, 2024
1 parent 82b2bb7 commit 09a0dcc
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 78 deletions.
82 changes: 43 additions & 39 deletions example/porous_media/duplicate_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,88 +5,92 @@
import glob

# Define the source image file
source_image1 = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/Porosity_Chi_distribution.png'
source_image2 = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/generated_kc_chi_permability_512x512.png'
# source_image1 = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/Porosity_Chi_distribution.png'
# source_image2 = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/generated_kc_chi_permability_512x512.png'



# Define the destination directory where the copied images will be saved
subdir = 'poro_study_kc_abs_normal_permability/'

# batch1
# subdir = 'poro_study_tanh_kc_chi_permability/'
# source_image1_hist = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/tanh_kc_permability_from_Chi_porosity.png'
# source_image2_background = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/generated_tanh_kc_chi_permability_512x512.png'


#batch2
# subdir = 'poro_study_porosity_chi_distribution/'
# source_image1_hist = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/Porosity_Chi_distribution.png'
# source_image2_background = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/generated_porosity_chi_distribution_512x512.png'

#batch3
subdir = 'poro_study_porosity_normal_distribution/'
source_image1_hist = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/Porosity_normal_distribution.png'
source_image2_background = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/generated_porosity_normal_distribution_512x512.png'


# DESTINATION
destination_directory = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/script_output/' + subdir

# Define the starting index for naming the copied images
start_index = 1000

# Define the number of times you want to copy the image

num_files_to_generate = len(os.listdir(destination_directory))

# num_files_to_generate = len(os.listdir(destination_directory))
num_files_to_generate = 333



# Loop through and copy the image N times
for i in range(num_files_to_generate):
new_filename = f'Porosity_Chi_distribution_{start_index + i +1}.png'
shutil.copyfile(source_image1, destination_directory + new_filename)
print(f'Copied {source_image1} to {destination_directory + new_filename}')
new_filename = f'imghist_{start_index + i +1}.png'
shutil.copyfile(source_image1_hist, destination_directory + new_filename)
print(f'Copied {source_image1_hist} to {destination_directory + new_filename}')

for i in range(num_files_to_generate):
new_filename = f'generated_kc_chi_permability_512x512_{start_index + i +1}.png'
shutil.copyfile(source_image2, destination_directory + new_filename)
print(f'Copied {source_image2} to {destination_directory + new_filename}')
new_filename = f'imgbackground_{start_index + i +1}.png'
shutil.copyfile(source_image2_background, destination_directory + new_filename)
print(f'Copied {source_image2_background} to {destination_directory + new_filename}')




print(f'Images copied successfully to {destination_directory}')

def join_images_side_by_side_cv(img1_path, img2_path, output_path):
def join_images_side_by_side_cv(img1_path, img2_path, img3_path, output_path):
image1 = cv2.imread(img1_path)
image2 = cv2.imread(img2_path)

image3 = cv2.imread(img3_path)
# Resize images to the same height
# height = min(image1.shape[0], image2.shape[0])
# image1 = cv2.resize(image1, (int(image1.shape[1] * height / image1.shape[0]), height))
# image2 = cv2.resize(image2, (int(image2.shape[1] * height / image2.shape[0]), height))
image2 = cv2.resize(image2, (512, 512))
image3 = cv2.resize(image3, (512, 512))

# Concatenate images horizontally
new_image = np.hstack((image1, image2))
new_image = np.hstack((image1, image2, image3))

# Save the new image
cv2.imwrite(output_path, new_image)


# image_pairs = [('path_to_image1_1.jpg', 'path_to_image1_2.jpg'), ('path_to_image2_1.jpg', 'path_to_image2_2.jpg')]


def list_and_sort_files(pattern):
"""List files matching the pattern and sort them."""
files = glob.glob(pattern)
files.sort()
return files


# for index, (img1_path, img2_path) in enumerate(image_pairs):
# join_images_side_by_side_cv(img1_path, img2_path, f'joined_image_{index+1}.jpg')


# List and sort the files
a_files = list_and_sort_files(destination_directory+'H_*.png')
b_files = list_and_sort_files(destination_directory+'Porosity_Chi_distribution_*.png')
H_files = list_and_sort_files(destination_directory+'H_*.png')
a_files = list_and_sort_files(destination_directory+'imgbackground_*.png')
b_files = list_and_sort_files(destination_directory+'imghist_*.png')


# Assuming both lists are the same length and correctly matched
counter =1000
for a_file, b_file in zip(a_files, b_files):
counter = counter + 1
output_filename = destination_directory+f"joined_{counter}.png" # Customize the output filename as needed
join_images_side_by_side_cv(a_file, b_file, output_filename)
print(f'joined {output_filename}')

a_files = list_and_sort_files(destination_directory+'joined_*.png')
b_files = list_and_sort_files(destination_directory+'generated_kc_chi_permability_512x512_*.png')

for a_file, b_file in zip(a_files, b_files):
for H_file, a_file, b_file in zip(H_files, a_files, b_files):
counter = counter + 1
output_filename = destination_directory+f"joined3_{counter}.png" # Customize the output filename as needed
join_images_side_by_side_cv(a_file, b_file, output_filename)
join_images_side_by_side_cv(H_file, a_file, b_file, output_filename)
print(f'joined {output_filename}')


Expand All @@ -109,4 +113,4 @@ def list_and_sort_files(pattern):
]

# Execute the ffmpeg command, automatically confirming any prompts
subprocess.run(ffmpeg_command, text=True, input='y\n')
subprocess.run(ffmpeg_command, text=True, input='y\n')
45 changes: 10 additions & 35 deletions example/porous_media/process_dir_vtk2png.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@
# directory_path= '/home/grzegorz/GITHUB/LBM/TCLB/output/poro_study/'

# file_path = 'd2q9_poro_study_121perm_VTK_P00_00002003.vti'
subdir = 'poro_study_kc_abs_normal_permability/'
# subdir = 'poro_study_kc_abs_normal_permability/'

# subdir = 'poro_study_tanh_kc_chi_permability/'
# subdir = 'poro_study_porosity_chi_distribution/'
subdir = 'poro_study_porosity_normal_distribution/'


directory_path = '/home/grzegorz/GITHUB/LBM/TCLB/output/' + subdir

# data_path = directory_path + file_path

shape = (512,512)
data_path = glob.glob(directory_path + '*.vti')[10]

shape = (512,512)
check_arrays(data_path)

data=getdata_1D(data_path, array_id=2, reader=reader, shape=shape)


colors = [(1, 1, 1), (0, 0, 1), (0, 0, 0)] # black, blue, white
n_bins = 1000 # Discretizes the interpolation into bins
cmap_name = 'custom_colormap'
cm = LinearSegmentedColormap.from_list(cmap_name, colors, N=n_bins)


make_plot(data, "title", cm, vmin=10.05, vmax=11, ticks=[10, 10.2, 10.4, 10.6, 10.8, 11])



make_plot(data, "title", cm, vmin=10.05, vmax=11, ticks=[10, 10.2, 10.4, 10.6, 10.8, 11])
save_img(data, h=shape[0], w=shape[1], cmap=cm, vmin=10, vmax=11, title=f'uff.png')

output_dir = 'script_output/' + subdir
Expand Down Expand Up @@ -89,34 +89,9 @@
'-b:v', '5M',
'-crf', '17',
'-pix_fmt', 'yuv420p',
f'{output_dir}output.mp4'
f'{output_dir}_ink_H_output.mp4'
]

# Execute the ffmpeg command, automatically confirming any prompts
subprocess.run(ffmpeg_command, text=True, input='y\n')

# Step 4: Plot the 2D field using matplotlib
# plt.figure(figsize=(14, 10))


# im = plt.imshow(data, cmap=cm, clim=(10, 11))
# im = plt.imshow(data, cmap='viridis') # You can change the colormap as needed
# plt.colorbar()

# cbar = plt.colorbar(im, orientation='horizontal', fraction=0.1, pad=0.1)
# cbar.set_label('Intensity') # You can customize the label

# plt.title('Velocity magnitude')

# plt.grid(which='major', color='#CCCCCC', linestyle='--')
# Optionally, you can customize the grid lines further
# plt.minorticks_on() # Enable minor ticks if needed
# plt.grid(which='minor', color='#CCCCCC', linestyle=':')
# plt.show()

# Loop through all *.vti files in the directory
# for file_path in glob.glob(directory_path + '*.vti'):
# print(file_path)
# # Add your processing logic for each file here

# %%
8 changes: 4 additions & 4 deletions example/porous_media/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ def make_histogram(img, nbins = 100, title="Grayscale Histogram", output_name="H


# ax.set_title(f"{title}")
ax.set_xlabel("Grayscale value")
# ax.set_xlabel("Grayscale value")
# ax.set_ylabel("Count")
# ax.set_xlim([-1.0, 1.0]) # <- named arguments do not work here
# ax.plot(bin_edges[:-1], histogram) # <- or here


# Turn off tick labels
ax.set_yticklabels([])
# ax.set_yticklabels([])
# ax.set_xticklabels([])
# to remove the tick marks as well as the label
# ax.set_xticks([])
ax.set_yticks([])
# ax.set_yticks([])

# Turn off y-axis ticks and labels
# ax.yaxis.set_visible(False)
ax.yaxis.set_ticklabels([])

ax.xaxis.set_ticklabels([])

# plt.gca().axes.get_yaxis().set_visible(False)
# plt.gca().axes.yaxis.set_ticklabels([])
Expand Down

0 comments on commit 09a0dcc

Please sign in to comment.