您可以检查,其中一些包含彩色信号,而某些只是灰色/黑色信号。我的任务是仅提取具有白色背景的纯信号。这意味着我需要除去图像中的所有信号。
我检查了虚线,虚线,实线(顶部和底部)具有相同的RGB值,它们接近0; 0; 0(例如:0; 0; 0、2; 2; 2;或8; 8; 8)的RGB。
因此,我想到的第一件事是访问每个像素的RGB值,如果所有RGB值都相同,则分配白色。使用大量计算,我可以提取所有颜色信号,因为对于红色,蓝色,绿色(或某种程度上的阴影)而言,RGB值永远不会相同。
但是,该过程将删除信号的像素值相同的信号。大多数黑色信号都会发生这种情况(例如,前两个样本)。
我还考虑过在保持水平和垂直连续性的情况下提取信号,但老实说,我不知道如何编写代码。
我没有要求任何代码解决方案来应对这一挑战。我想对如何成功提取原始信号有不同的意见。
我期待着您的想法,见解和消息来源。谢谢
注意:我所有的图像(大约3k)都在一个文件夹中,我将应用一种通用算法来完成任务。
您可以使用Hough transform找到水平线和垂直线。找到这些线之后,很容易将它们擦除。
删除线条只是第一步,但这看起来是一个很好的起点...保持彩色像素(按照您的建议)也是简单的任务。
您已经提到您没有要求任何代码解决方案,但我决定使用MATLAB代码来证明我的建议:
close all
clear
origI = imread('I.png'); %Read image
I = imbinarize(rgb2gray(origI)); %Convert to binary
I = ~I; %Invert - the line color should be white.
%Apply hough transform: Find lines with angles very close to 0 degrees and with angles close to 90 degrees.
[H,theta,rho] = hough(I, 'RhoResolution', 1, 'Theta', [-0.3:0.02:0.3, -90:0.02:-89.7, 89.7:0.02:89.98]);
P = houghpeaks(H, numel(H), 'Threshold', 0.1, 'NHoodSize', [11, 1]); %Use low thresholds
lines = houghlines(I,theta,rho,P,'FillGap',25,'MinLength',200); %Fill large gaps and keep only the long lines.
%Plot the lines for debugging, and erase them by drawing black lines over them
J = im2uint8(I);
figure, imshow(I), hold on
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Draw black line over each line.
J = insertShape(J, 'Line', [xy(1,1), xy(1,2), xy(2,1), xy(2,2)], 'Color', 'Black');
end
%Covert J image to binary (because MATLAB function insertShape returns RGB output).
J = imbinarize(rgb2gray(J));
figure, imshow(J)
%Color mask: 1 where color is not black or white.
I = double(origI);
C = (abs(I(:,:,1) - I(:,:,2)) > 20) | (abs(I(:,:,1) - I(:,:,3)) > 20) | (abs(I(:,:,2) - I(:,:,3)) > 20);
figure, imshow(C)
%Build a mask that combines "lines" mask and "color" mask.
Mask = J | C;
Mask = cat(3, Mask, Mask, Mask);
%Put white color where mask value is 0.
K = origI;
K(~Mask) = 255;
figure, imshow(K)
您可以看到仍然有剩菜剩饭。我对以上结果进行了第二次迭代(相同的代码)。
您可以尝试使用形态学操作删除残over剩饭。不删除虚线图将很困难。