skimage 转换为灰度导致黑色图像
skimage convert to grayscale resulting to a black image
我正在抓取图像并尝试将它们转换为灰度。但如果我查看图像。它是纯黑色的。有人能告诉我这有什么问题吗?谢谢
这是我的片段
import cv2
from skimage import io
from skimage import data
from skimage.color import rgb2gray
#...some codes
for i in elements:
try:
i.click()
except ElementClickInterceptedException:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
i.click()
url = driver.find_element_by_xpath('//*[@class="slider-list"]/div/img').get_attribute('src').replace('height=600','height=1200').replace('quality=70','quality=100')
print (url)
name = driver.find_element_by_xpath('//*[@class="slider-list"]/div/img').get_attribute('alt') + '.jpg'
print (name)
img = io.imread(url)
new = rgb2gray(img)
cv2.imwrite(os.path.join(fldrnm, name), new)
Import cv2
Img = cv2.inread(filepath)
Img = cv2.cvtColor(Img, cv2.COLOR_RGB2GRAY)
cv2.imwrite(path,img)
问题的最初原因是 skimage.color.rgb2gray
会将图像重新缩放为 [0, 1] 中的浮点值,即使原始图像包含 [0, 255] 中的 uint8 值也是如此。这样做是为了在长时间的操作序列中保持精度。在原始问题中使用 skimage.io.imsave
而不是 cv2.imwrite
是可行的,在保存之前使用 skimage.util.img_as_ubyte
也是如此。
查看此页面了解更多详情:
https://scikit-image.org/docs/dev/user_guide/data_types.html
我正在抓取图像并尝试将它们转换为灰度。但如果我查看图像。它是纯黑色的。有人能告诉我这有什么问题吗?谢谢
这是我的片段
import cv2
from skimage import io
from skimage import data
from skimage.color import rgb2gray
#...some codes
for i in elements:
try:
i.click()
except ElementClickInterceptedException:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
i.click()
url = driver.find_element_by_xpath('//*[@class="slider-list"]/div/img').get_attribute('src').replace('height=600','height=1200').replace('quality=70','quality=100')
print (url)
name = driver.find_element_by_xpath('//*[@class="slider-list"]/div/img').get_attribute('alt') + '.jpg'
print (name)
img = io.imread(url)
new = rgb2gray(img)
cv2.imwrite(os.path.join(fldrnm, name), new)
Import cv2
Img = cv2.inread(filepath)
Img = cv2.cvtColor(Img, cv2.COLOR_RGB2GRAY)
cv2.imwrite(path,img)
问题的最初原因是 skimage.color.rgb2gray
会将图像重新缩放为 [0, 1] 中的浮点值,即使原始图像包含 [0, 255] 中的 uint8 值也是如此。这样做是为了在长时间的操作序列中保持精度。在原始问题中使用 skimage.io.imsave
而不是 cv2.imwrite
是可行的,在保存之前使用 skimage.util.img_as_ubyte
也是如此。
查看此页面了解更多详情:
https://scikit-image.org/docs/dev/user_guide/data_types.html