过度绿色提取实现
excessive green color extraction implementation
我想将图像像素分割成植被和非植被。对于这种过多的绿色提取算法是developed.the算法如下所示。
Outimage (x,y,z) = inimage (x,y,z)
if { inimage (x,y,r) < (x,y,g) inimage (x,y,b) < (x,y,g) }
outimage(x,y,z) = 0 否则*
其中outimage(x,y,z)为过度绿色分割后的输出图像,保存为jpg格式,inimage(x,y,z)为相机获取的图像,x为像素点数每行,y 是每列中的像素数,z 是原色平面,对于红色,z 等于 1,对于绿色,z 为 2,对于蓝色,z 为 3。
我不知道如何实现这个所以请帮助我实现it.or只是给我一些粗略的想法或建议我如何实现它。
输入图像:
输出:
我希望在应用上述算法后输出为这种格式
构建一个 2D 蒙版,然后使用 bsxfun
将其应用于所有颜色分量(第三维切片):
inimage = imread('filename'); %// type uint8
mask = inimage(:,:,1)<inimage(:,:,2) & inimage(:,:,3)<inimage(:,:,2); %// 2D mask
outimage = bsxfun(@times, inimage, uint8(mask)); %// apply mask replicated along 3rd dim
另一种解决方案是将图像转换为 HSV colorspace 如果您不熟悉它,它将 RGB 值转换为色调(颜色)、饱和度(颜色的鲜艳程度)、~亮度(照明水平)。这样做的好处是您可以在所有照明条件下寻找相同的颜色。
除了我们如何获得遮罩(使用绿色色调)之外,它与 rgb 版本的过程完全相同
inimage = imread('plants.png');
hsv_im = rgb2hsv(inimage);
%plots only the hues so we can get an idea of what to segment out
hue_channel = 1;
figure(1)
imshow(hsv_im(:,:,hue_channel)); %displays only the hue channel/layer
colormap(hsv) %uses the hue colormap
colorbar %displays the colorbar
%masks the greenish regions (this is subjective)
mask = hsv_im(:,:,hue_channel) < 0.5 & hsv_im(:,:,hue_channel) > 0.2;
%applies the mask to all 3 color layers
outimage = bsxfun(@times, inimage, uint8(mask));
figure(2)
subplot(1,2,1);imshow(inimage);title('original image')
subplot(1,2,2),imshow(outimage);title('segmented image')
我想将图像像素分割成植被和非植被。对于这种过多的绿色提取算法是developed.the算法如下所示。
Outimage (x,y,z) = inimage (x,y,z)
if { inimage (x,y,r) < (x,y,g) inimage (x,y,b) < (x,y,g) }
outimage(x,y,z) = 0 否则*
其中outimage(x,y,z)为过度绿色分割后的输出图像,保存为jpg格式,inimage(x,y,z)为相机获取的图像,x为像素点数每行,y 是每列中的像素数,z 是原色平面,对于红色,z 等于 1,对于绿色,z 为 2,对于蓝色,z 为 3。
我不知道如何实现这个所以请帮助我实现it.or只是给我一些粗略的想法或建议我如何实现它。
输入图像:
输出:
我希望在应用上述算法后输出为这种格式
构建一个 2D 蒙版,然后使用 bsxfun
将其应用于所有颜色分量(第三维切片):
inimage = imread('filename'); %// type uint8
mask = inimage(:,:,1)<inimage(:,:,2) & inimage(:,:,3)<inimage(:,:,2); %// 2D mask
outimage = bsxfun(@times, inimage, uint8(mask)); %// apply mask replicated along 3rd dim
另一种解决方案是将图像转换为 HSV colorspace 如果您不熟悉它,它将 RGB 值转换为色调(颜色)、饱和度(颜色的鲜艳程度)、~亮度(照明水平)。这样做的好处是您可以在所有照明条件下寻找相同的颜色。
除了我们如何获得遮罩(使用绿色色调)之外,它与 rgb 版本的过程完全相同
inimage = imread('plants.png');
hsv_im = rgb2hsv(inimage);
%plots only the hues so we can get an idea of what to segment out
hue_channel = 1;
figure(1)
imshow(hsv_im(:,:,hue_channel)); %displays only the hue channel/layer
colormap(hsv) %uses the hue colormap
colorbar %displays the colorbar
%masks the greenish regions (this is subjective)
mask = hsv_im(:,:,hue_channel) < 0.5 & hsv_im(:,:,hue_channel) > 0.2;
%applies the mask to all 3 color layers
outimage = bsxfun(@times, inimage, uint8(mask));
figure(2)
subplot(1,2,1);imshow(inimage);title('original image')
subplot(1,2,2),imshow(outimage);title('segmented image')