danhtran2mind commited on
Commit
56d5114
·
verified ·
1 Parent(s): 70e8f53

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +49 -26
README.md CHANGED
@@ -22,19 +22,18 @@ cd autoencoder-grayscale2color-landscape
22
  git lfs pull
23
  ```
24
  ### Import Libraries
25
- ```bash
26
  from PIL import Image
27
  import os
28
  import numpy as np
29
  import tensorflow as tf
30
  import requests
31
  from skimage.color import lab2rgb
32
-
33
  from models.auto_encoder_gray2color import SpatialAttention
34
-
35
  ```
36
  ### Load Model file
37
- ```bash
38
  # Load the saved model once at startup
39
  load_model_path = "./ckpts/best_model.h5"
40
 
@@ -45,24 +44,8 @@ loaded_autoencoder = tf.keras.models.load_model(
45
  )
46
  ```
47
 
48
- ### Inferenc Step
49
  ```python
50
- # Assuming process_image function is defined as provided
51
- # and required imports (tensorflow, skimage.color for lab2rgb) are available
52
-
53
- def display_images_pil(input_path):
54
- # Read input image
55
- input_img = Image.open(input_path)
56
-
57
- # Process the image using the provided function
58
- output_img = process_image(input_img)
59
-
60
- # Display input image
61
- input_img.show(title="Input Image")
62
-
63
- # Display output image
64
- output_img.show(title="Output Image")
65
-
66
  def process_image(input_img):
67
  # Store original input dimensions
68
  original_width, original_height = input_img.size
@@ -94,10 +77,50 @@ def process_image(input_img):
94
 
95
  return rgb_image
96
 
 
 
 
 
 
 
 
 
 
 
 
97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  # Example usage
99
- if __name__ == "__main__":
100
- # Replace 'input_image.jpg' with the path to your image
101
- image_path = "<input_image.jpg>"
102
- display_images_pil(image_path)
103
- ```
 
 
 
 
 
 
22
  git lfs pull
23
  ```
24
  ### Import Libraries
25
+ ```python
26
  from PIL import Image
27
  import os
28
  import numpy as np
29
  import tensorflow as tf
30
  import requests
31
  from skimage.color import lab2rgb
32
+ import matplotlib.pyplot as plt
33
  from models.auto_encoder_gray2color import SpatialAttention
 
34
  ```
35
  ### Load Model file
36
+ ```python
37
  # Load the saved model once at startup
38
  load_model_path = "./ckpts/best_model.h5"
39
 
 
44
  )
45
  ```
46
 
47
+ ### Define Functions
48
  ```python
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  def process_image(input_img):
50
  # Store original input dimensions
51
  original_width, original_height = input_img.size
 
77
 
78
  return rgb_image
79
 
80
+ def process_and_plot_images(input_path):
81
+ # Read input image
82
+ input_img = Image.open(input_path)
83
+
84
+ # Process the image (placeholder for your process_image function)
85
+ output_img = process_image(input_img)
86
+
87
+ # Save output image to output.jpg
88
+ output_img.save("output.jpg")
89
+
90
+ return input_img, output_img
91
 
92
+ def plot_in_out_images(input_img, output_img):
93
+ # Create a figure with two subplots for input and output images
94
+ plt.figure(figsize=(17, 8), dpi=300) # Set DPI to 300
95
+
96
+ # Plot input image
97
+ plt.subplot(1, 2, 1)
98
+ plt.imshow(input_img, cmap='gray')
99
+ plt.title("Input Image")
100
+ plt.axis('off') # Hide axes for cleaner display
101
+
102
+ # Plot output image
103
+ plt.subplot(1, 2, 2)
104
+ plt.imshow(output_img, cmap='gray')
105
+ plt.title("Output Image")
106
+ plt.axis('off') # Hide axes for cleaner display
107
+
108
+ # Save the figure as output.jpg with 300 DPI
109
+ plt.savefig("output.jpg", dpi=300, bbox_inches='tight')
110
+
111
+ # Show the plot
112
+ plt.show()
113
+ ```
114
+ ### Inference
115
+ ```python
116
  # Example usage
117
+ WIDTH, HEIGHT = 512, 512
118
+ # Replace 'input_image.jpg' with the path to your image
119
+ image_path = "<input_image.jpg>"
120
+ input_img, output_img = process_and_plot_images(image_path)
121
+
122
+ plot_in_out_images(input_img, output_img)
123
+ ```
124
+
125
+ ### Example Output
126
+ ![Plot Image](./examples/model_output.jpg)