简体   繁体   English

识别图像中不连续出现的最暗颜色

[英]Identify darkest color that occurs noncontigously in an image

I am looking for a way to identify the dark grey ovals on this example image:我正在寻找一种方法来识别此示例图像上的深灰色椭圆:

在此处输入图片说明

I know I can find the darkest color in the image with a simple min .我知道我可以用一个简单的min找到图像中最暗的颜色。 However, I am not interested in identifying the black in this example (darkest, contiguous part of the image).但是,我对识别此示例中的黑色(图像的最暗、连续部分)不感兴趣。 Therefore, I think my problem can be described: identifying the darkest color in the image that occurs noncontigously .因此,我认为我的问题可以描述为:识别图像中非连续出现的最暗颜色。 That is, the dark grey ovals in the example above.即,上例中的深灰色椭圆。 I would appreciate your help.我会很感激你的帮助。 Notice how there's some noise also in the image, that I would ideally not take into account when find this darkest noncontiguous color.请注意图像中还有一些噪点,当找到这种最暗的非连续颜色时,我最好不要考虑这些噪点。 However, that might be different step/too much for this question.但是,对于这个问题,这可能是不同的步骤/太多了。

I've been messing with output from regionprops to achieve this goal.我一直在搞乱regionprops输出来实现这个目标。 However, I am not sure how to combine that output with color data.但是,我不确定如何将该输出与颜色数据结合起来。 I was wondering if there is some MATLAB tool, or some image processing trick that would make this task easier.我想知道是否有一些 MATLAB 工具或一些图像处理技巧可以使这项任务更容易。

Thanks in adavnce!预先感谢!

If the expected range/tones of grey to be extracted is known image thresholding can be applied to eliminate all the bodies that are not of that unique colour/tone.如果要提取的灰色的预期范围/色调是已知的,则可以应用图像阈值来消除所有不是那种独特颜色/色调的主体。 Here I converted the image to greyscale and filtered out the noise in the image using a median filter.在这里,我将图像转换为greyscale并使用中值滤波器过滤掉图像中的噪声。

Image 1: Lower_Threshold : 125 and Upper_Threshold : 240图 1: Lower_Threshold :125 和Upper_Threshold :240

颜色形状检测 1

Image 2: Lower_Threshold : 20 and Upper_Threshold :160图 2: Lower_Threshold : 20 和Upper_Threshold :160

颜色形状检测2

  File_Name = "Ovals.png";

    Image = imread(File_Name);
    Greyscale_Image = rgb2gray(Image);
    
    %Filtering out some noise%
    Filtered_Image = medfilt2(Greyscale_Image, [10 10]);
    
    [Image_Height,Image_Width,Depth] = size(Image);
    
    Lower_Threshold = 125;
    Upper_Threshold = 140;
    
    
    %Thresholding the signal%
    for Row_Scanner = 1: +1: Image_Height
       for Column_Scanner = 1: +1: Image_Width 
        
        Pixel_Value = Filtered_Image(Row_Scanner,Column_Scanner);
        if(Pixel_Value > Upper_Threshold)
        Filtered_Image(Row_Scanner,Column_Scanner) = 255;    
        end
        
        if(Pixel_Value < Lower_Threshold)
            Filtered_Image(Row_Scanner,Column_Scanner) = 255;    
        end
        
       end
    end
    
    Filtered_Image = medfilt2(Filtered_Image, [10 10]);
    imshow(Filtered_Image);

Additional Sobel Edge Detection:额外的 Sobel 边缘检测:

Lowering the Upper_Threshold can filter out more data that is not of interest.降低Upper_Threshold可以过滤掉更多不感兴趣的数据。

边缘检测

File_Name = "PCA_Image.png";
Image = imread(File_Name);
Greyscale_Image = Image;

[Image_Height,Image_Width,Depth] = size(Image);

Lower_Threshold = 0;
Upper_Threshold = 50;

%Thresholding the sig6al%
for Row_Scanner = 1: +1: Image_Height
   for Column_Scanner = 1: +1: Image_Width 
    
    Pixel_Value = Greyscale_Image(Row_Scanner,Column_Scanner);
    if(Pixel_Value > Upper_Threshold)
    Greyscale_Image(Row_Scanner,Column_Scanner) = 255;    
    end
    
    if(Pixel_Value < Lower_Threshold)
        Greyscale_Image(Row_Scanner,Column_Scanner) = 255;    
    end
    
   end
end

Binary_Image = Greyscale_Image < 255;
Edge_Image = edge(Greyscale_Image,'sobel');


subplot(1,2,1); imshow(Binary_Image); 
subplot(1,2,2); imshow(Edge_Image);

These are steps you need to take to extract darker ovals from the image you provided:这些是从您提供的图像中提取较暗椭圆所需的步骤:

  1. Import the image导入图像
  2. Turn it to black and white so you call regionprops and extract shape properties把它变成黑白,这样你就可以调用regionprops并提取形状属性
  3. Select the regions by their properties按属性选择区域
  4. Find the darkest color from selected regions从选定区域中找到最深的颜色
clc; close all; clear variables;
% import the image
I = im2double(rgb2gray(imread('KtzM7.png')));

% convert the image to balck and white
BW = (1-I)>0.05;

% extract shape and intensity properties of 
% connected components
stats = regionprops(BW, I, 'MinorAxisLength', ...
    'MajorAxisLength', 'Area', 'MeanIntensity');
% filter components by theis extend and area
ratio = [stats.MinorAxisLength] ./ [stats.MajorAxisLength];
[~, circleLike] = find((ratio > 0.65) & ([stats.Area] > 30));

% extract regions of interest in the image
L = bwlabel(BW);
RoI = ismember(L, circleLike);

% find the lowest intensity among RoI
intensities = [stats.MeanIntensity];
darkest = min(intensities(circleLike));

% remove non-RoI regions from output
O = max(I, 1-RoI);

% remove components that their intensity is not 
% equal to darkest color
O(abs(O-darkest)>0.1) = 1;

subplot 221, imshow(I), title('Input Image')
subplot 222, imshow(BW), title('Black & White')
subplot 223, imshow(RoI), title('Region of Interest');
subplot 224, imshow(O), title('Output Image')

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM