質問編集履歴

1

追記しました。

2021/01/11 03:59

投稿

gomsis
gomsis

スコア11

test CHANGED
File without changes
test CHANGED
@@ -9,6 +9,12 @@
9
9
 
10
10
 
11
11
  書き出したものを毎回読み込むと処理が遅くなるのではないかと思っており、書き出さずに動かせる何かいい方法をご存じであれば教えていただけると助かります。よろしくお願いいたします。
12
+
13
+
14
+
15
+ ###追記
16
+
17
+ 参考にさせていただいたサイトより、訂正したところチャンネルが異なるとエラーが出てしまいました。解決方法があればお教えいただきたいです。
12
18
 
13
19
 
14
20
 
@@ -24,21 +30,29 @@
24
30
 
25
31
  error Traceback (most recent call last)
26
32
 
27
- <ipython-input-4-702949269155> in <module>
33
+ <ipython-input-12-ae6612370064> in <module>
34
+
35
+ 23
28
36
 
29
37
  24 #contrast
30
38
 
31
- 25 clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
39
+ ---> 25 lab = cv2.cvtColor(img2, cv2.COLOR_BGR2LAB)
32
40
 
33
- ---> 26 cl1 = clahe.apply(img2)
41
+ 26 lab_planes = cv2.split(img2)
34
42
 
35
- 27 cv2.imwrite("back-cl.jpg",cl1)
43
+ 27 clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
36
-
37
- 28
38
44
 
39
45
 
40
46
 
41
- error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-71670poj\opencv\modules\imgproc\src\clahe.cpp:351: error: (-215:Assertion failed) _src.type() == CV_8UC1 || _src.type() == CV_16UC1 in function '`anonymous-namespace'::CLAHE_Impl::apply'
47
+ error: OpenCV(4.4.0) c:\users\appveyor\appdata\local\temp\1\pip-req-build-71670poj\opencv\modules\imgproc\src\color.simd_helpers.hpp:92: error: (-2:Unspecified error) in function '__cdecl cv::impl::`anonymous-namespace'::CvtHelper<struct cv::impl::`anonymous namespace'::Set<3,4,-1>,struct cv::impl::A0x2b0558ac::Set<3,-1,-1>,struct cv::impl::A0x2b0558ac::Set<0,5,-1>,2>::CvtHelper(const class cv::_InputArray &,const class cv::_OutputArray &,int)'
48
+
49
+ > Invalid number of channels in input image:
50
+
51
+ > 'VScn::contains(scn)'
52
+
53
+ > where
54
+
55
+ > 'scn' is 1
42
56
 
43
57
  ```
44
58
 
@@ -58,9 +72,25 @@
58
72
 
59
73
  import numpy as np
60
74
 
75
+ import openpyxl as excel
61
76
 
62
77
 
78
+
79
+ #backgroundimagecreation
80
+
81
+ #img read
82
+
83
+ oimg = cv2.imread('back.jpg',0)
84
+
63
- import openpyxl as excel
85
+ height = oimg.shape[0]
86
+
87
+ width = oimg.shape[1]
88
+
89
+ resize_img = cv2.resize(oimg,(int(width*0.5),int(height*0.5)))
90
+
91
+
92
+
93
+ #ganma
64
94
 
65
95
  img_blur = cv2.GaussianBlur(resize_img,(499,499),0)
66
96
 
@@ -84,9 +114,17 @@
84
114
 
85
115
  #contrast
86
116
 
117
+ lab = cv2.cvtColor(img2, cv2.COLOR_BGR2LAB)
118
+
119
+ lab_planes = cv2.split(img2)
120
+
87
121
  clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
88
122
 
89
- cl1 = clahe.apply(img2)
123
+ lab_planes[0] = clahe.apply(lab_planes[0])
124
+
125
+ lab = cv2.merge(lab_planes)
126
+
127
+ cl1 = cv2.cvtColor(lab, cv2.COLOR_LAB2BGR)
90
128
 
91
129
  cv2.imwrite("back-cl.jpg",cl1)
92
130