
在此图像中,我需要检测车辆轮辋并通过图像处理测量轮辋的像素长度.我想我应该遵循循环Hough变换的圆圈.你能告诉我哪些步骤可以获得轮辋的宽度?ex(灰度 - >边缘检测,或对此的任何其他评论)
image-processing edge-detection grayscale hough-transform threshold
字节数组以这种方式获得 -
BufferedImage image = new Robot().createScreenCapture(new Rectangle(screenDimension));
byte[] array = ((DataBufferByte)getGraycaleImage(image).getRaster().getDataBuffer()).getData();
// Method getGraycaleImage returns a grayscaled BufferedImage, it works fine
Run Code Online (Sandbox Code Playgroud)
现在我如何从字节数组重建这个灰度图像?
我对ARGB,RGB或灰度图像知之甚少.我试过这个 -
private Image getGrayscaleImageFromArray(byte[] pixels, int width, int height)
{
int[] pixels2=getIntArrayFromByteArray(pixels);
MemoryImageSource mis = new MemoryImageSource(width, height, pixels2, 0, width);
Toolkit tk = Toolkit.getDefaultToolkit();
return tk.createImage(mis);
}
private int[] getIntArrayFromByteArray(byte[] pixelsByte)
{
int[] pixelsInt=new int[pixelsByte.length];
int i;
for(i=0;i<pixelsByte.length;i++)
pixelsInt[i]=pixelsByte[i]<<24 | pixelsByte[i]<<16
| pixelsByte[i]<<8 | pixelsByte[i]; // I think this line creates the problem
return pixelsInt; …Run Code Online (Sandbox Code Playgroud) 据我所知,我正在使用此代码(使用 skimage 版本 0.10.0),没有问题:
from scipy import misc
import scipy.io as sio
from skimage.color import rgb2gray
img = cv2.imread(myfile)
img = rgb2gray(img)
Run Code Online (Sandbox Code Playgroud)
但现在我收到此错误:
Traceback (most recent call last):
File "C:\work_asaaki\code\generateProposals.py", line 48, in <module>
img = rgb2gray(img)
File "C:\Anaconda\lib\site-packages\skimage\color\colorconv.py", line 635, in rgb2gray
if rgb.ndim == 2:
AttributeError: 'NoneType' object has no attribute 'ndim'
Run Code Online (Sandbox Code Playgroud)
可能是什么问题?如何修复它才能将图像转换为灰度?
我想让我的背景图像半透明,灰度/黑白.我通过组合来自Stackoverflow的两个不同线程的代码来制作以下代码
body {
position: relative;
background-size: 100% 100%;
background-repeat: no-repeat;
}
body::after {
content: "";
background: url('<?php echo $background[0]; ?>');
opacity: 0.5;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
filter: grayscale(100%); /* Current draft standard */
-webkit-filter: grayscale(100%); /* New WebKit */
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%); /* Not yet supported in Gecko, Opera or IE */
filter: url(resources.svg#desaturate); /* Gecko */
filter: gray; /* IE */
-webkit-filter: grayscale(1); /* Old WebKit */
} …Run Code Online (Sandbox Code Playgroud) 我想有一个ImageButton是最初有一个灰色的效果就可以了&轮流到其选择时原来的颜色。我正在努力实现类似的目标
. 我知道这可以在 CSS 中完成,但想知道是否存在与它等效的任何 Android 属性/函数。
我在这里读了一篇文章,似乎暗示我必须维护同一图像的不同灰色副本才能实现这一目标。但是,如果我有 100 个以上的 ImageButton,那么维护同一个 Image 的 2 个副本会消耗大量内存。
与常规 Button 不同,ImageButton 或具有图像背景的 Button 在禁用时不会变灰。您实际上必须使用另一个图像或以它看起来变灰的方式对其进行处理。
那么真的没有办法在 Android 中实现在 CSS 中使用灰度可以实现的目标吗?
感谢您的时间!!
我正在尝试将 UIImage 转换为灰度。它所产生的只是一个完全黑色的图像。
func convertToGrayScale2(image: UIImage) -> UIImage {
let imageRect:CGRect = CGRect(x:0, y:0, width:image.size.width, height: image.size.height)
let colorSpace = CGColorSpaceCreateDeviceGray()
let width = image.size.width
let height = image.size.height
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.none.rawValue)
let context = CGContext(data: nil, width: Int(width), height: Int(height), bitsPerComponent: 8, bytesPerRow: 0, space: colorSpace, bitmapInfo: bitmapInfo.rawValue)
let imageRef = context!.makeImage()
context?.draw(imageRef!, in: imageRect)
let newImage = UIImage(cgImage: imageRef!)
return newImage
}
Run Code Online (Sandbox Code Playgroud)
代码有什么问题吗?我需要现有代码的帮助。它之前正在工作。突然它不工作了。
import glob
import cv2
import os
import numpy as np
from PIL import Image
images=[]
images=np.array(images)
path='C:\Users\Quantum\Desktop\test'
count=0
images = [cv2.imread(file,0) for file in glob.glob("E:\homework\Computer vision\Faces\*.jpg")]
for i in range(len(images)):
# im = Image.fromarray(images[i])
# cv2.imwrite(str(path) + '.jpg', images[count])
cv2.imwrite(os.path.join(path, 'pic.jpg'), images[count])
count+=1
Run Code Online (Sandbox Code Playgroud)
尝试从文件夹中选择所有图像,图像被选择并转换为灰度,尽管我不知道如何将这些图像写入特定文件夹。请帮忙
使用此代码:
import cv2
import matplotlib.pyplot as plt
%matplotlib inline
plt.imshow(cv2.imread('badger.jpeg' , cv2.IMREAD_GRAYSCALE))
Run Code Online (Sandbox Code Playgroud)
将图像读取为灰度并绘制到屏幕.
图像绘制为:
这似乎不是灰度,因为渲染图像中包含的颜色范围不是白色到灰色?
我的代码使用IMREAD_GRAYSCALE参数将图像作为灰度读取是否正确?
该图片位于:https://sciencing.com/difference-between-badger-wolverine-8645505.html
我有很多灰度图像要使用均值和标准差进行归一化。我使用以下过程:
计算图像的均值和标准差。
从图像中减去平均值。
将结果图像除以标准偏差。
但是,结果我得到了一个黑色图像。我的代码有什么问题?
import cv2
img = cv2.imread('E.png') # read an image
gray_image = cv2.cvtColor(img , cv2.COLOR_BGR2GRAY) # converting the image to grayscale image
img = cv2.resize(gray_image, (60, 60)) # Resize the image to the size 60x60 pixels
cv2.imwrite("Grayscale Image.png",img) #To write the result
mean, stdDev = cv2.meanStdDev(img) #Get Mean and Standard-deviation
image = (img-mean)/stdDev #Normalization process
cv2.imwrite("Normalized Image.png",image) #To write the result
Run Code Online (Sandbox Code Playgroud)
输入图像: 
灰度输出: 
归一化图像输出: 