juyam commited on
Commit
a9bf145
·
1 Parent(s): 89878c5

another bugfix

Browse files

error was

image = cv2.imread(input_image.name, cv2.IMREAD_COLOR)
AttributeError: 'numpy.ndarray' object has no attribute 'name'

Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -7,28 +7,26 @@ remapped_R = [39, 44, 44, 40, 43, 45, 46, 46, 50, 49, 48, 52, 49, 51, 51, 52, 53
7
  remapped_G = [28, 29, 29, 32, 32, 34, 35, 35, 35, 37, 35, 36, 38, 40, 40, 41, 41, 43, 43, 43, 45, 47, 47, 48, 48, 50, 51, 52, 52, 53, 40, 58, 58, 59, 60, 60, 63, 63, 65, 65, 66, 70, 68, 71, 49, 50, 51, 51, 51, 52, 52, 53, 86, 88, 55, 55, 56, 57, 96, 98, 100, 100, 100, 106, 106, 107, 110, 111, 112, 113, 115, 116, 118, 119, 121, 122, 123, 125, 126, 126, 128, 129, 130, 131, 132, 134, 135, 136, 136, 138, 137, 137, 140, 138, 143, 143, 145, 145, 147, 147, 148, 150, 150, 151, 150, 154, 152, 152, 156, 153, 156, 159, 156, 158, 158, 160, 160, 160, 162, 162, 159, 164, 166, 164, 167, 167, 169, 168, 168, 171, 144, 171, 172, 174, 173, 174, 174, 178, 176, 177, 178, 180, 180, 180, 180, 181, 182, 182, 183, 183, 184, 186, 186, 187, 188, 187, 190, 191, 191, 192, 192, 191, 194, 193, 193, 196, 197, 196, 197, 197, 199, 199, 199, 200, 203, 202, 201, 203, 204, 205, 205, 206, 198, 207, 207, 208, 209, 208, 210, 211, 212, 212, 213, 213, 214, 213, 215, 215, 216, 216, 218, 218, 210, 219, 219, 221, 221, 221, 222, 223, 224, 224, 224, 226, 225, 226, 226, 227, 228, 228, 230, 230, 230, 232, 232, 232, 233, 234, 234, 235, 236, 237, 240, 240, 238, 238, 239, 240, 241, 242, 241, 242, 244, 244, 244, 245, 245, 246, 247, 248, 249, 249, 250, 251, 251, 251]
8
  remapped_B = [26, 30, 29, 30, 32, 30, 32, 30, 34, 35, 32, 36, 35, 38, 38, 38, 40, 41, 40, 41, 43, 46, 41, 46, 49, 49, 47, 32, 51, 34, 34, 34, 58, 36, 38, 39, 40, 40, 42, 65, 43, 70, 74, 70, 73, 75, 50, 79, 81, 82, 83, 86, 90, 90, 90, 91, 94, 96, 95, 100, 98, 100, 105, 105, 97, 97, 111, 110, 112, 115, 116, 118, 119, 121, 122, 122, 124, 125, 126, 129, 129, 130, 133, 133, 134, 135, 136, 137, 137, 137, 139, 140, 141, 143, 143, 144, 145, 147, 150, 150, 151, 151, 154, 155, 152, 155, 155, 158, 158, 158, 159, 160, 162, 162, 164, 162, 164, 165, 165, 166, 168, 168, 168, 169, 172, 172, 172, 173, 173, 174, 176, 176, 176, 177, 177, 178, 180, 180, 180, 182, 183, 183, 184, 186, 185, 185, 186, 188, 188, 186, 190, 189, 183, 190, 191, 194, 194, 193, 195, 195, 197, 197, 198, 198, 200, 200, 200, 176, 203, 202, 203, 204, 205, 203, 203, 206, 208, 208, 208, 208, 209, 210, 212, 212, 212, 212, 213, 214, 215, 215, 216, 216, 216, 217, 217, 218, 218, 218, 222, 222, 222, 222, 222, 223, 221, 224, 224, 225, 225, 227, 227, 227, 228, 228, 230, 230, 231, 231, 232, 232, 232, 234, 234, 235, 235, 237, 237, 238, 234, 234, 238, 239, 240, 240, 241, 241, 242, 243, 243, 242, 245, 246, 246, 246, 246, 247, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252]
9
 
10
- def remap_image(input_image):
11
- # 画像を読み込む
12
- image = cv2.imread(input_image.name, cv2.IMREAD_COLOR)
13
 
14
- # 画像と同じサイズの黒い画像を作成
15
- remapped_image = np.zeros_like(image)
 
16
 
17
  # 画像のサイズを取得
18
- height, width, _ = image.shape
19
 
20
  # 画像の各ピクセルの色をリマップ
21
  for r in range(height):
22
  for c in range(width):
23
- b1, g1, r1 = image[r][c]
24
  remapped_image[r][c] = (remapped_B[b1], remapped_G[g1], remapped_R[r1])
25
 
26
  # 画像を出力
27
  return remapped_image
28
 
29
  # Gradio UI を定義
30
- image_input = gr.Image(label="Input Image")
31
- image_output = gr.Image(label="Remapped Image")
32
 
33
  # Gradioインターフェースを作成
34
- gr.Interface(fn=remap_image, inputs=image_input, outputs=image_output, title="Image Remapper").launch()
 
7
  remapped_G = [28, 29, 29, 32, 32, 34, 35, 35, 35, 37, 35, 36, 38, 40, 40, 41, 41, 43, 43, 43, 45, 47, 47, 48, 48, 50, 51, 52, 52, 53, 40, 58, 58, 59, 60, 60, 63, 63, 65, 65, 66, 70, 68, 71, 49, 50, 51, 51, 51, 52, 52, 53, 86, 88, 55, 55, 56, 57, 96, 98, 100, 100, 100, 106, 106, 107, 110, 111, 112, 113, 115, 116, 118, 119, 121, 122, 123, 125, 126, 126, 128, 129, 130, 131, 132, 134, 135, 136, 136, 138, 137, 137, 140, 138, 143, 143, 145, 145, 147, 147, 148, 150, 150, 151, 150, 154, 152, 152, 156, 153, 156, 159, 156, 158, 158, 160, 160, 160, 162, 162, 159, 164, 166, 164, 167, 167, 169, 168, 168, 171, 144, 171, 172, 174, 173, 174, 174, 178, 176, 177, 178, 180, 180, 180, 180, 181, 182, 182, 183, 183, 184, 186, 186, 187, 188, 187, 190, 191, 191, 192, 192, 191, 194, 193, 193, 196, 197, 196, 197, 197, 199, 199, 199, 200, 203, 202, 201, 203, 204, 205, 205, 206, 198, 207, 207, 208, 209, 208, 210, 211, 212, 212, 213, 213, 214, 213, 215, 215, 216, 216, 218, 218, 210, 219, 219, 221, 221, 221, 222, 223, 224, 224, 224, 226, 225, 226, 226, 227, 228, 228, 230, 230, 230, 232, 232, 232, 233, 234, 234, 235, 236, 237, 240, 240, 238, 238, 239, 240, 241, 242, 241, 242, 244, 244, 244, 245, 245, 246, 247, 248, 249, 249, 250, 251, 251, 251]
8
  remapped_B = [26, 30, 29, 30, 32, 30, 32, 30, 34, 35, 32, 36, 35, 38, 38, 38, 40, 41, 40, 41, 43, 46, 41, 46, 49, 49, 47, 32, 51, 34, 34, 34, 58, 36, 38, 39, 40, 40, 42, 65, 43, 70, 74, 70, 73, 75, 50, 79, 81, 82, 83, 86, 90, 90, 90, 91, 94, 96, 95, 100, 98, 100, 105, 105, 97, 97, 111, 110, 112, 115, 116, 118, 119, 121, 122, 122, 124, 125, 126, 129, 129, 130, 133, 133, 134, 135, 136, 137, 137, 137, 139, 140, 141, 143, 143, 144, 145, 147, 150, 150, 151, 151, 154, 155, 152, 155, 155, 158, 158, 158, 159, 160, 162, 162, 164, 162, 164, 165, 165, 166, 168, 168, 168, 169, 172, 172, 172, 173, 173, 174, 176, 176, 176, 177, 177, 178, 180, 180, 180, 182, 183, 183, 184, 186, 185, 185, 186, 188, 188, 186, 190, 189, 183, 190, 191, 194, 194, 193, 195, 195, 197, 197, 198, 198, 200, 200, 200, 176, 203, 202, 203, 204, 205, 203, 203, 206, 208, 208, 208, 208, 209, 210, 212, 212, 212, 212, 213, 214, 215, 215, 216, 216, 216, 217, 217, 218, 218, 218, 222, 222, 222, 222, 222, 223, 221, 224, 224, 225, 225, 227, 227, 227, 228, 228, 230, 230, 231, 231, 232, 232, 232, 234, 234, 235, 235, 237, 237, 238, 234, 234, 238, 239, 240, 240, 241, 241, 242, 243, 243, 242, 245, 246, 246, 246, 246, 247, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252]
9
 
 
 
 
10
 
11
+ def remap_image(input_image):
12
+ # 画像の各ピクセルのR、G、B値をリマップ
13
+ remapped_image = np.zeros_like(input_image)
14
 
15
  # 画像のサイズを取得
16
+ height, width, _ = input_image.shape
17
 
18
  # 画像の各ピクセルの色をリマップ
19
  for r in range(height):
20
  for c in range(width):
21
+ b1, g1, r1 = input_image[r][c]
22
  remapped_image[r][c] = (remapped_B[b1], remapped_G[g1], remapped_R[r1])
23
 
24
  # 画像を出力
25
  return remapped_image
26
 
27
  # Gradio UI を定義
28
+ image_input = gr.Image()
29
+ image_output = gr.Image()
30
 
31
  # Gradioインターフェースを作成
32
+ gr.Interface(fn=remap_image, inputs=image_input, outputs=image_output, title="Image Remapper").launch()