Skip to content

Commit 09a0dcc

Browse files
committed
img order
1 parent 82b2bb7 commit 09a0dcc

File tree

3 files changed

+57
-78
lines changed

3 files changed

+57
-78
lines changed

example/porous_media/duplicate_image.py

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,88 +5,92 @@
55
import glob
66

77
# Define the source image file
8-
source_image1 = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/Porosity_Chi_distribution.png'
9-
source_image2 = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/generated_kc_chi_permability_512x512.png'
8+
# source_image1 = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/Porosity_Chi_distribution.png'
9+
# source_image2 = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/generated_kc_chi_permability_512x512.png'
10+
11+
1012

1113
# Define the destination directory where the copied images will be saved
12-
subdir = 'poro_study_kc_abs_normal_permability/'
14+
15+
# batch1
16+
# subdir = 'poro_study_tanh_kc_chi_permability/'
17+
# source_image1_hist = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/tanh_kc_permability_from_Chi_porosity.png'
18+
# source_image2_background = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/generated_tanh_kc_chi_permability_512x512.png'
19+
20+
21+
#batch2
22+
# subdir = 'poro_study_porosity_chi_distribution/'
23+
# source_image1_hist = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/Porosity_Chi_distribution.png'
24+
# source_image2_background = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/generated_porosity_chi_distribution_512x512.png'
25+
26+
#batch3
27+
subdir = 'poro_study_porosity_normal_distribution/'
28+
source_image1_hist = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/Porosity_normal_distribution.png'
29+
source_image2_background = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/generated_porosity_normal_distribution_512x512.png'
30+
31+
32+
# DESTINATION
1333
destination_directory = '/home/grzegorz/GITHUB/LBM/TCLB/example/porous_media/script_output/' + subdir
1434

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

1838
# Define the number of times you want to copy the image
19-
20-
num_files_to_generate = len(os.listdir(destination_directory))
21-
39+
# num_files_to_generate = len(os.listdir(destination_directory))
2240
num_files_to_generate = 333
2341

24-
25-
2642
# Loop through and copy the image N times
2743
for i in range(num_files_to_generate):
28-
new_filename = f'Porosity_Chi_distribution_{start_index + i +1}.png'
29-
shutil.copyfile(source_image1, destination_directory + new_filename)
30-
print(f'Copied {source_image1} to {destination_directory + new_filename}')
44+
new_filename = f'imghist_{start_index + i +1}.png'
45+
shutil.copyfile(source_image1_hist, destination_directory + new_filename)
46+
print(f'Copied {source_image1_hist} to {destination_directory + new_filename}')
3147

3248
for i in range(num_files_to_generate):
33-
new_filename = f'generated_kc_chi_permability_512x512_{start_index + i +1}.png'
34-
shutil.copyfile(source_image2, destination_directory + new_filename)
35-
print(f'Copied {source_image2} to {destination_directory + new_filename}')
49+
new_filename = f'imgbackground_{start_index + i +1}.png'
50+
shutil.copyfile(source_image2_background, destination_directory + new_filename)
51+
print(f'Copied {source_image2_background} to {destination_directory + new_filename}')
3652

3753

3854

3955

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

42-
def join_images_side_by_side_cv(img1_path, img2_path, output_path):
58+
def join_images_side_by_side_cv(img1_path, img2_path, img3_path, output_path):
4359
image1 = cv2.imread(img1_path)
4460
image2 = cv2.imread(img2_path)
45-
61+
image3 = cv2.imread(img3_path)
4662
# Resize images to the same height
4763
# height = min(image1.shape[0], image2.shape[0])
4864
# image1 = cv2.resize(image1, (int(image1.shape[1] * height / image1.shape[0]), height))
4965
# image2 = cv2.resize(image2, (int(image2.shape[1] * height / image2.shape[0]), height))
5066
image2 = cv2.resize(image2, (512, 512))
67+
image3 = cv2.resize(image3, (512, 512))
68+
5169
# Concatenate images horizontally
52-
new_image = np.hstack((image1, image2))
70+
new_image = np.hstack((image1, image2, image3))
5371

5472
# Save the new image
5573
cv2.imwrite(output_path, new_image)
56-
57-
58-
# image_pairs = [('path_to_image1_1.jpg', 'path_to_image1_2.jpg'), ('path_to_image2_1.jpg', 'path_to_image2_2.jpg')]
5974

6075

6176
def list_and_sort_files(pattern):
6277
"""List files matching the pattern and sort them."""
6378
files = glob.glob(pattern)
6479
files.sort()
6580
return files
66-
67-
68-
# for index, (img1_path, img2_path) in enumerate(image_pairs):
69-
# join_images_side_by_side_cv(img1_path, img2_path, f'joined_image_{index+1}.jpg')
70-
81+
7182
# List and sort the files
72-
a_files = list_and_sort_files(destination_directory+'H_*.png')
73-
b_files = list_and_sort_files(destination_directory+'Porosity_Chi_distribution_*.png')
83+
H_files = list_and_sort_files(destination_directory+'H_*.png')
84+
a_files = list_and_sort_files(destination_directory+'imgbackground_*.png')
85+
b_files = list_and_sort_files(destination_directory+'imghist_*.png')
86+
7487

7588
# Assuming both lists are the same length and correctly matched
7689
counter =1000
77-
for a_file, b_file in zip(a_files, b_files):
78-
counter = counter + 1
79-
output_filename = destination_directory+f"joined_{counter}.png" # Customize the output filename as needed
80-
join_images_side_by_side_cv(a_file, b_file, output_filename)
81-
print(f'joined {output_filename}')
82-
83-
a_files = list_and_sort_files(destination_directory+'joined_*.png')
84-
b_files = list_and_sort_files(destination_directory+'generated_kc_chi_permability_512x512_*.png')
85-
86-
for a_file, b_file in zip(a_files, b_files):
90+
for H_file, a_file, b_file in zip(H_files, a_files, b_files):
8791
counter = counter + 1
8892
output_filename = destination_directory+f"joined3_{counter}.png" # Customize the output filename as needed
89-
join_images_side_by_side_cv(a_file, b_file, output_filename)
93+
join_images_side_by_side_cv(H_file, a_file, b_file, output_filename)
9094
print(f'joined {output_filename}')
9195

9296

@@ -109,4 +113,4 @@ def list_and_sort_files(pattern):
109113
]
110114

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

example/porous_media/process_dir_vtk2png.py

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@
1717
# directory_path= '/home/grzegorz/GITHUB/LBM/TCLB/output/poro_study/'
1818

1919
# file_path = 'd2q9_poro_study_121perm_VTK_P00_00002003.vti'
20-
subdir = 'poro_study_kc_abs_normal_permability/'
20+
# subdir = 'poro_study_kc_abs_normal_permability/'
21+
22+
# subdir = 'poro_study_tanh_kc_chi_permability/'
23+
# subdir = 'poro_study_porosity_chi_distribution/'
24+
subdir = 'poro_study_porosity_normal_distribution/'
25+
26+
2127
directory_path = '/home/grzegorz/GITHUB/LBM/TCLB/output/' + subdir
2228

2329
# data_path = directory_path + file_path
24-
30+
shape = (512,512)
2531
data_path = glob.glob(directory_path + '*.vti')[10]
2632

27-
shape = (512,512)
2833
check_arrays(data_path)
29-
3034
data=getdata_1D(data_path, array_id=2, reader=reader, shape=shape)
3135

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

3841

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

4545
output_dir = 'script_output/' + subdir
@@ -89,34 +89,9 @@
8989
'-b:v', '5M',
9090
'-crf', '17',
9191
'-pix_fmt', 'yuv420p',
92-
f'{output_dir}output.mp4'
92+
f'{output_dir}_ink_H_output.mp4'
9393
]
9494

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

98-
# Step 4: Plot the 2D field using matplotlib
99-
# plt.figure(figsize=(14, 10))
100-
101-
102-
# im = plt.imshow(data, cmap=cm, clim=(10, 11))
103-
# im = plt.imshow(data, cmap='viridis') # You can change the colormap as needed
104-
# plt.colorbar()
105-
106-
# cbar = plt.colorbar(im, orientation='horizontal', fraction=0.1, pad=0.1)
107-
# cbar.set_label('Intensity') # You can customize the label
108-
109-
# plt.title('Velocity magnitude')
110-
111-
# plt.grid(which='major', color='#CCCCCC', linestyle='--')
112-
# Optionally, you can customize the grid lines further
113-
# plt.minorticks_on() # Enable minor ticks if needed
114-
# plt.grid(which='minor', color='#CCCCCC', linestyle=':')
115-
# plt.show()
116-
117-
# Loop through all *.vti files in the directory
118-
# for file_path in glob.glob(directory_path + '*.vti'):
119-
# print(file_path)
120-
# # Add your processing logic for each file here
121-
122-
# %%

example/porous_media/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@ def make_histogram(img, nbins = 100, title="Grayscale Histogram", output_name="H
3333

3434

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

4141

4242
# Turn off tick labels
43-
ax.set_yticklabels([])
43+
# ax.set_yticklabels([])
4444
# ax.set_xticklabels([])
4545
# to remove the tick marks as well as the label
4646
# ax.set_xticks([])
47-
ax.set_yticks([])
47+
# ax.set_yticks([])
4848

4949
# Turn off y-axis ticks and labels
5050
# ax.yaxis.set_visible(False)
5151
ax.yaxis.set_ticklabels([])
52-
52+
ax.xaxis.set_ticklabels([])
5353

5454
# plt.gca().axes.get_yaxis().set_visible(False)
5555
# plt.gca().axes.yaxis.set_ticklabels([])

0 commit comments

Comments
 (0)