我必须创建一个线性灰度渐变,顶部为黑色阴影,底部为白色阴影。我必须使用 skimage 和 numpy。
我在 scikit 上找到了水平而不是垂直的颜色线性渐变的代码:http://scikit-image.org/docs/dev/auto_examples/plot_tinting_grayscale_images.html。
我想要对此代码的解释以及有关如何将所有内容置于灰度和垂直而不是彩色和水平的一些提示。谢谢!
我需要将 PNGH*W*4 rgba图像转换为rgbshape 的图像H*W*3。
我可以做到这一点,但是当我保存它时,图像会再次保存,如下H*W*4
是代码片段:
for idx, image in enumerate(image_names):
#matplotlib as mpi here I use plt for plotting and mpi for read
rgba = mpi.imread(os.path.join(read_path,image))
#convert to rgb using skimage.color as rtl,
rgb = rtl.rgba2rgb(rgba)
#change path of the image to be saved
resized_path = os.path.join(os.path.sep,Ims,p[0],image)
print(np.shape(rgb))#shape is printed (136,136,3)
mpi.imsave(resized_path,rgb)
Run Code Online (Sandbox Code Playgroud)
在此之后,当我再次阅读它时,它的形状又是H*W*4任何想法为什么?imsave我猜matplotlib 有什么东西吗?
参考图片:
像这样编辑更新的代码:
for idx, image in enumerate(image_names):
rgba = plt.imread(os.path.join(read_path,image))
rgb = skimage.color.rgba2rgb(rgba) …Run Code Online (Sandbox Code Playgroud) 我有两张图片,一张有 Alpha 通道,另一张没有。因此, imageA和 分别B具有(x,y,4)和(x,y,3)的形状。
我想使用 将两个图像合并到一个张量中python,其中B是背景,A是上图。最终图像的形状必须为 (x, y, 3)。我试过 scikit-image 或 cv2 是否能够做到这一点,但我找不到任何解决方案。
StackOverflow 上已经有几种解决方案来解码和编码图像和 base64 字符串。但是他们中的大多数都需要磁盘之间的IO,这很浪费时间。是否有任何解决方案可以仅在内存中进行编码和解码?
这基本上与此处发布的问题相同:如何使用 PIL 将透明 png 图像与另一个图像合并,但使用 scikit-image 而不是 PIL。我的意思是将 png 粘贴在背景图像的顶部,并保持其透明度。另外,如果真的有办法做到这一点,我想知道哪个更快(PIL 或 scikit-image)。谢谢。
我正在尝试在 Python 中读取 tiff 文件的标签。该文件是 RGB,每个通道具有uint16值。我目前正在使用tifffile:
import tifffile
img = tifffile.imread('file.tif')
Run Code Online (Sandbox Code Playgroud)
然而,img是一个 numpy 数组,它只有像素值。例如,我如何读取图像的x_resolution?
我尝试使用 skimage 将 RGB 转换为 HSV 并获得我不期望的行为。这是我希望只产生蓝色的一些示例代码。这很重要(稍后),因为我想拍摄真实图像并通过参考色调来确定整个图像中每种颜色的存在量。
import numpy as np
import skimage as ski
import matplotlib.pyplot as plt
#define my own color in RGB, should be B
tested = np.ones(shape=(100,100,3))*200
tested[:,:,0] =0
tested[:,:,1] =0
hsv_test_img_arr=ski.color.rgb2hsv(tested)
hue_img = hsv_test_img_arr[:, :, 0]
sat_img = hsv_test_img_arr[:, :, 1]
value_img = hsv_test_img_arr[:, :, 2]
fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(8, 2))
ax1.imshow(hue_img, cmap='hsv')
ax1.set_title('hue channel')
ax1.axis('off')
ax2.imshow(value_img)
ax2.set_title('value channel')
ax2.axis('off')
ax3.imshow(sat_img)
ax3.set_title('sat channel')
ax3.axis('off')
Run Code Online (Sandbox Code Playgroud)
我运行以下代码来创建一个矩形轮廓:
#import the necessary packages
import argparse
import imutils
import cv2
import numpy as np
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to the input image")
args = vars(ap.parse_args())
# load the image, convert it to grayscale, blur it slightly, and threshold it
image = cv2.imread(args["image"])
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (5, 5), 0)
# threshold the image, then perform a series of erosions + dilations to remove any …Run Code Online (Sandbox Code Playgroud) 我的一位同事在对图像进行分类时在 python 服务中出错。下面是错误跟踪日志
File "nsfw.py", line 7, in <module>
score = classifier.get_score('8.jpg')
File "/home/arunsharma/.local/lib/python3.6/site-packages/open_nsfw_python3/__init__.py", line 104, in get_score
image_data, caffe_transformer=caffe_transformer, caffe_net=nsfw_net, output_layers=['prob'])
File "/home/arunsharma/.local/lib/python3.6/site-packages/open_nsfw_python3/__init__.py", line 52, in caffe_preprocess_and_compute
image = caffe.io.load_image(img_data_rs)
File "/usr/lib/python3/dist-packages/caffe/io.py", line 301, in load_image
img = skimage.img_as_float(skimage.io.imread(filename, as_grey=not color)).astype(np.float32)
File "/home/arunsharma/.local/lib/python3.6/site-packages/skimage/io/_io.py", line 48, in imread
img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
File "/home/arunsharma/.local/lib/python3.6/site-packages/skimage/io/manage_plugins.py", line 210, in call_plugin
return func(*args, **kwargs)
File "/home/arunsharma/.local/lib/python3.6/site-packages/skimage/io/_plugins/imageio_plugin.py", line 10, in imread
return np.asarray(imageio_imread(*args, **kwargs))
File "/home/arunsharma/.local/lib/python3.6/site-packages/imageio/core/functions.py", line 264, in imread
reader = …Run Code Online (Sandbox Code Playgroud)