質問編集履歴

3

インデントを修正しました。

2018/12/08 15:57

投稿

terertail
terertail

スコア12

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  ###ソースコード
2
2
 
3
- '''
3
+ ```
4
4
 
5
5
  #import the necessary packages
6
6
 
@@ -144,7 +144,7 @@
144
144
 
145
145
  compare_images(original, shopped, "Original vs. Photoshopped")
146
146
 
147
- '''
147
+ ```
148
148
 
149
149
  ###
150
150
 
@@ -166,7 +166,7 @@
166
166
 
167
167
  ### 発生している問題・エラーメッセージ
168
168
 
169
- '''
169
+ ```
170
170
 
171
171
  Traceback (most recent call last):
172
172
 
@@ -176,7 +176,7 @@
176
176
 
177
177
  ImportError: cannot import name structural_similarity
178
178
 
179
- '''
179
+ ```
180
180
 
181
181
  ### 試したこと
182
182
 

2

インデントを修正しました。

2018/12/08 15:57

投稿

terertail
terertail

スコア12

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,6 @@
1
1
  ###ソースコード
2
+
3
+ '''
2
4
 
3
5
  #import the necessary packages
4
6
 
@@ -142,7 +144,7 @@
142
144
 
143
145
  compare_images(original, shopped, "Original vs. Photoshopped")
144
146
 
145
-
147
+ '''
146
148
 
147
149
  ###
148
150
 
@@ -164,7 +166,7 @@
164
166
 
165
167
  ### 発生している問題・エラーメッセージ
166
168
 
167
-
169
+ '''
168
170
 
169
171
  Traceback (most recent call last):
170
172
 
@@ -173,6 +175,8 @@
173
175
  from skimage.measure import structural_similarity as ssim
174
176
 
175
177
  ImportError: cannot import name structural_similarity
178
+
179
+ '''
176
180
 
177
181
  ### 試したこと
178
182
 

1

ソースコードの表示がおかしかったのでその変更

2018/12/08 15:55

投稿

terertail
terertail

スコア12

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,152 @@
1
+ ###ソースコード
2
+
3
+ #import the necessary packages
4
+
5
+ from skimage.measure import structural_similarity as ssim
6
+
7
+ import matplotlib.pyplot as plt
8
+
9
+ import numpy as np
10
+
11
+ import cv2
12
+
13
+ %matplotlib inline
14
+
15
+
16
+
17
+ def mse(imageA, imageB):
18
+
19
+ #the 'Mean Squared Error' between the two images is the
20
+
21
+ #sum of the squared difference between the two images;
22
+
23
+ #NOTE: the two images must have the same dimension
24
+
25
+ err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
26
+
27
+ err /= float(imageA.shape[0] * imageA.shape[1])
28
+
29
+
30
+
31
+ #return the MSE, the lower the error, the more "similar"
32
+
33
+ #the two images are
34
+
35
+ return err
36
+
37
+
38
+
39
+ def compare_images(imageA, imageB, title):
40
+
41
+ #compute the mean squared error and structural similarity
42
+
43
+ #index for the images
44
+
45
+ m = mse(imageA, imageB)
46
+
47
+ s = ssim(imageA, imageB)
48
+
49
+
50
+
51
+ #setup the figure
52
+
53
+ fig = plt.figure(title)
54
+
55
+ plt.suptitle("MSE: %.2f, SSIM: %.2f" % (m, s))
56
+
57
+
58
+
59
+ #show first image
60
+
61
+ ax = fig.add_subplot(1, 2, 1)
62
+
63
+ plt.imshow(imageA, cmap = plt.cm.gray)
64
+
65
+ plt.axis("off")
66
+
67
+
68
+
69
+ #show the second image
70
+
71
+ ax = fig.add_subplot(1, 2, 2)
72
+
73
+ plt.imshow(imageB, cmap = plt.cm.gray)
74
+
75
+ plt.axis("off")
76
+
77
+
78
+
79
+ #show the images
80
+
81
+ plt.show()
82
+
83
+
84
+
85
+ #load the images -- the original, the original + contrast,
86
+
87
+ #and the original + photoshop
88
+
89
+ original = cv2.imread("resize/re_pic006.jpg")
90
+
91
+ contrast = cv2.imread("resize/re_pic005.jpg")
92
+
93
+ shopped = cv2.imread("resize/re_pic003.jpg")
94
+
95
+
96
+
97
+ #convert the images to grayscale
98
+
99
+ original = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
100
+
101
+ contrast = cv2.cvtColor(contrast, cv2.COLOR_BGR2GRAY)
102
+
103
+ shopped = cv2.cvtColor(shopped, cv2.COLOR_BGR2GRAY)
104
+
105
+
106
+
107
+ #initialize the figure
108
+
109
+ fig = plt.figure("Images")
110
+
111
+ images = ("Original", original), ("Contrast", contrast), ("Photoshopped", shopped)
112
+
113
+
114
+
115
+ #loop over the images
116
+
117
+ for (i, (name, image)) in enumerate(images):
118
+
119
+ #show the image
120
+
121
+ ax = fig.add_subplot(1, 3, i + 1)
122
+
123
+ ax.set_title(name)
124
+
125
+ plt.imshow(image, cmap = plt.cm.gray)
126
+
127
+ plt.axis("off")
128
+
129
+
130
+
131
+ #show the figure
132
+
133
+ plt.show()
134
+
135
+
136
+
137
+ #compare the images
138
+
139
+ compare_images(original, original, "Original vs. Original")
140
+
141
+ compare_images(original, contrast, "Original vs. Contrast")
142
+
143
+ compare_images(original, shopped, "Original vs. Photoshopped")
144
+
145
+
146
+
147
+ ###
148
+
1
- ### 前提・実現しこと
149
+ ### やったこと
2
150
 
3
151
 
4
152
 
@@ -6,9 +154,7 @@
6
154
 
7
155
  上記のページの「以下は、類似度計算の実行用コードとなります。」
8
156
 
9
- 以降のプログラムを実行した際invalid syntaxエラーを吐かれ
157
+ 以降のプログラムを実行した際
10
-
11
- エラーを吐いたところをコメント化して実行したら
12
158
 
13
159
  以下のようなエラーが起こりました。
14
160
 
@@ -26,163 +172,7 @@
26
172
 
27
173
  from skimage.measure import structural_similarity as ssim
28
174
 
29
- ImportError: cannot import name 'structural_similarity' from 'skimage.measure' (C:\Anaconda3\envs\nnabla\lib\site-packages\skimage\measure\__init__.py)
30
-
31
-
32
-
33
-
34
-
35
- ### 該当のソースコード
36
-
37
-
38
-
39
- # import the necessary packages
40
-
41
- from skimage.measure import structural_similarity as ssim
42
-
43
- import matplotlib.pyplot as plt
44
-
45
- import numpy as np
46
-
47
- import cv2
48
-
49
- #matplotlib inline
50
-
51
- ↑最初は%matplotlib inlineでした。
52
-
53
- そして実行するとinvalid syntaxエラーが起きました。
54
-
55
-
56
-
57
- def mse(imageA, imageB):
58
-
59
- # the 'Mean Squared Error' between the two images is the
60
-
61
- # sum of the squared difference between the two images;
62
-
63
- # NOTE: the two images must have the same dimension
64
-
65
- err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
66
-
67
- err /= float(imageA.shape[0] * imageA.shape[1])
68
-
69
-
70
-
71
- # return the MSE, the lower the error, the more "similar"
72
-
73
- # the two images are
74
-
75
- return err
76
-
77
-
78
-
79
- def compare_images(imageA, imageB, title):
80
-
81
- # compute the mean squared error and structural similarity
175
+ ImportError: cannot import name structural_similarity
82
-
83
- # index for the images
84
-
85
- m = mse(imageA, imageB)
86
-
87
- s = ssim(imageA, imageB)
88
-
89
-
90
-
91
- # setup the figure
92
-
93
- fig = plt.figure(title)
94
-
95
- plt.suptitle("MSE: %.2f, SSIM: %.2f" % (m, s))
96
-
97
-
98
-
99
- # show first image
100
-
101
- ax = fig.add_subplot(1, 2, 1)
102
-
103
- plt.imshow(imageA, cmap = plt.cm.gray)
104
-
105
- plt.axis("off")
106
-
107
-
108
-
109
- # show the second image
110
-
111
- ax = fig.add_subplot(1, 2, 2)
112
-
113
- plt.imshow(imageB, cmap = plt.cm.gray)
114
-
115
- plt.axis("off")
116
-
117
-
118
-
119
- # show the images
120
-
121
- plt.show()
122
-
123
-
124
-
125
- # load the images -- the original, the original + contrast,
126
-
127
- # and the original + photoshop
128
-
129
- original = cv2.imread("resize/re_pic006.jpg")
130
-
131
- contrast = cv2.imread("resize/re_pic005.jpg")
132
-
133
- shopped = cv2.imread("resize/re_pic003.jpg")
134
-
135
-
136
-
137
- # convert the images to grayscale
138
-
139
- original = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
140
-
141
- contrast = cv2.cvtColor(contrast, cv2.COLOR_BGR2GRAY)
142
-
143
- shopped = cv2.cvtColor(shopped, cv2.COLOR_BGR2GRAY)
144
-
145
-
146
-
147
- # initialize the figure
148
-
149
- fig = plt.figure("Images")
150
-
151
- images = ("Original", original), ("Contrast", contrast), ("Photoshopped", shopped)
152
-
153
-
154
-
155
- # loop over the images
156
-
157
- for (i, (name, image)) in enumerate(images):
158
-
159
- # show the image
160
-
161
- ax = fig.add_subplot(1, 3, i + 1)
162
-
163
- ax.set_title(name)
164
-
165
- plt.imshow(image, cmap = plt.cm.gray)
166
-
167
- plt.axis("off")
168
-
169
-
170
-
171
- # show the figure
172
-
173
- plt.show()
174
-
175
-
176
-
177
- # compare the images
178
-
179
- compare_images(original, original, "Original vs. Original")
180
-
181
- compare_images(original, contrast, "Original vs. Contrast")
182
-
183
- compare_images(original, shopped, "Original vs. Photoshopped")
184
-
185
-
186
176
 
187
177
  ### 試したこと
188
178
 
@@ -192,10 +182,14 @@
192
182
 
193
183
  なので#でコメント化した。
194
184
 
185
+ python3.7でやっていたので元ページと同じくpython2.7にした。
186
+
195
187
 
196
188
 
197
189
  ### 補足情報(FW/ツールのバージョンなど)
198
190
 
191
+ pip install ssimをやって、
199
192
 
193
+ ssim-0.2.2
200
194
 
201
- ここにより詳細な情報記載てください
195
+ インストール