Nekshay commited on
Commit
1848ec3
·
verified ·
1 Parent(s): 8f1e0df

Update New_file.txt

Browse files
Files changed (1) hide show
  1. New_file.txt +28 -10
New_file.txt CHANGED
@@ -7,26 +7,44 @@ image2_path = 'path_to_your_second_image.jpg'
7
  image1 = cv2.imread(image1_path)
8
  image2 = cv2.imread(image2_path)
9
 
10
- # Resize images to the same height for concatenation
11
- height1, width1, _ = image1.shape
12
- height2, width2, _ = image2.shape
13
-
14
  # Define the desired height for both images (e.g., height of the first image)
15
- desired_height = height1
 
 
 
 
 
 
 
16
 
17
  # Resize images
18
- image1_resized = cv2.resize(image1, (width1, desired_height))
19
- image2_resized = cv2.resize(image2, (width2, desired_height))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  # Combine images side by side
22
- combined_image = np.hstack((image1_resized, image2_resized))
23
 
24
  # Add labels to the top of each image
25
  label1 = 'Image 1'
26
  label2 = 'Image 2'
27
  font = cv2.FONT_HERSHEY_SIMPLEX
28
  font_scale = 1
29
- color = (255, 255, 255) # White color for the text
30
  thickness = 2
31
 
32
  # Calculate the position for the labels
@@ -38,7 +56,7 @@ x1 = 10
38
  y1 = label1_size[1] + 10
39
 
40
  # Position for label2
41
- x2 = width1 + 10
42
  y2 = label2_size[1] + 10
43
 
44
  # Add labels to the combined image
 
7
  image1 = cv2.imread(image1_path)
8
  image2 = cv2.imread(image2_path)
9
 
 
 
 
 
10
  # Define the desired height for both images (e.g., height of the first image)
11
+ desired_height = max(image1.shape[0], image2.shape[0])
12
+
13
+ # Function to resize an image while maintaining aspect ratio
14
+ def resize_with_aspect_ratio(image, height):
15
+ aspect_ratio = image.shape[1] / image.shape[0]
16
+ new_width = int(height * aspect_ratio)
17
+ resized_image = cv2.resize(image, (new_width, height))
18
+ return resized_image
19
 
20
  # Resize images
21
+ image1_resized = resize_with_aspect_ratio(image1, desired_height)
22
+ image2_resized = resize_with_aspect_ratio(image2, desired_height)
23
+
24
+ # Add white padding to make the images the same width
25
+ max_width = max(image1_resized.shape[1], image2_resized.shape[1])
26
+ image1_padded = cv2.copyMakeBorder(
27
+ image1_resized,
28
+ 0, 0, 0, max_width - image1_resized.shape[1],
29
+ cv2.BORDER_CONSTANT,
30
+ value=[255, 255, 255]
31
+ )
32
+ image2_padded = cv2.copyMakeBorder(
33
+ image2_resized,
34
+ 0, 0, 0, max_width - image2_resized.shape[1],
35
+ cv2.BORDER_CONSTANT,
36
+ value=[255, 255, 255]
37
+ )
38
 
39
  # Combine images side by side
40
+ combined_image = np.hstack((image1_padded, image2_padded))
41
 
42
  # Add labels to the top of each image
43
  label1 = 'Image 1'
44
  label2 = 'Image 2'
45
  font = cv2.FONT_HERSHEY_SIMPLEX
46
  font_scale = 1
47
+ color = (0, 0, 0) # Black color for the text
48
  thickness = 2
49
 
50
  # Calculate the position for the labels
 
56
  y1 = label1_size[1] + 10
57
 
58
  # Position for label2
59
+ x2 = image1_padded.shape[1] + 10
60
  y2 = label2_size[1] + 10
61
 
62
  # Add labels to the combined image