低对比度图像的对象提取
Object extraction for a low contrast image
我有一张对比度很低的图像,我想从中提取一个文本对象。由于对比度低,我尝试了几种方法,但没有一种方法给我满意的结果。我使用 watershed
提取文本对象,但由于对比度太差,提取不成功。
我的 watershed
计划是:
I_cropped=imread(strcat('C:\Id\',currentfilename));
I_cropped = rgb2gray(I_cropped);
I_eq = histeq(I_cropped);
figure,imshow(I_eq);
bw = im2bw(I_eq, graythresh(I_eq));
bw2 = imfill(bw,'holes');
bw3 = imopen(bw2, ones(5,5));
bw4 = bwareaopen(bw3, 40);
bw = im2bw(I_eq, graythresh(I_eq));
figure,imshow(bw);
mask_em = imextendedmax(I_eq, 30);
mask_em = imclose(mask_em, ones(5,5));
mask_em = imfill(mask_em, 'holes');
mask_em = bwareaopen(mask_em, 40);
figure,imshow(mask_em);
I_eq_c = imcomplement(I_eq);
figure,imshow(I_eq_c);
I_mod = imimposemin(I_eq_c, ~bw4 | mask_em);
figure,imshow(I_mod);
L = watershed(I_mod);
figure,imshow(label2rgb(L));
我应用了 laplacian
滤镜来增强边缘,但效果不佳。
我的objective是提取文本对象。对于这样低对比度的图像,我应该尝试什么方法?
附上图片:
这是一种方法。
首先在图像上应用具有大内核的中值滤波器以去除异常值,然后应用阈值转换为二值图像。请注意,使用过滤器的内核大小会改变您需要使用的阈值级别。试用它以查看输出变化。
然后反转图像并应用regionprops
检测图像中的物体。之后用一点数学推导出 x 和 y 原点(定义左上角)以及包含图像中所有字母的大边界框的宽度和长度。
代码如下:
clear
clc
close all
Im = rgb2gray(imread('Imtext.png'));
%// Apply median filter to remove outliers
Im = medfilt2(Im,[9 9]);
%// Clear borders and apply threshold, then invert image
ImBW = imclearborder(~(im2bw(Im,.55)));
%// Find bounding boxes to delineate text regions.
S = regionprops(ImBW,'BoundingBox');
%// Concatenate all bounding boxes and obtain x,y, width and length of big
%// bounding box enclosing everything
bb = cat(1,S.BoundingBox);
LargeBB_x = min(bb(:,1));
LargeBB_y = min(bb(:,2));
LargeBB_height = max(bb(:,4));
%// Find last column in which pixel value is 1; that's the end
%// of the bounding box.
[~,ic] = find(ImBW==1);
MaxCol = max(ic(:));
LargeBB_width = MaxCol-LargeBB_x;
%// Display boxes
imshow(ImBW)
hold on
rectangle('Position',[LargeBB_x LargeBB_y LargeBB_width LargeBB_height],'EdgeColor','r','LineWidth',2)
hold off
并且输出:
或用原图:
我有一张对比度很低的图像,我想从中提取一个文本对象。由于对比度低,我尝试了几种方法,但没有一种方法给我满意的结果。我使用 watershed
提取文本对象,但由于对比度太差,提取不成功。
我的 watershed
计划是:
I_cropped=imread(strcat('C:\Id\',currentfilename));
I_cropped = rgb2gray(I_cropped);
I_eq = histeq(I_cropped);
figure,imshow(I_eq);
bw = im2bw(I_eq, graythresh(I_eq));
bw2 = imfill(bw,'holes');
bw3 = imopen(bw2, ones(5,5));
bw4 = bwareaopen(bw3, 40);
bw = im2bw(I_eq, graythresh(I_eq));
figure,imshow(bw);
mask_em = imextendedmax(I_eq, 30);
mask_em = imclose(mask_em, ones(5,5));
mask_em = imfill(mask_em, 'holes');
mask_em = bwareaopen(mask_em, 40);
figure,imshow(mask_em);
I_eq_c = imcomplement(I_eq);
figure,imshow(I_eq_c);
I_mod = imimposemin(I_eq_c, ~bw4 | mask_em);
figure,imshow(I_mod);
L = watershed(I_mod);
figure,imshow(label2rgb(L));
我应用了 laplacian
滤镜来增强边缘,但效果不佳。
我的objective是提取文本对象。对于这样低对比度的图像,我应该尝试什么方法?
附上图片:
这是一种方法。
首先在图像上应用具有大内核的中值滤波器以去除异常值,然后应用阈值转换为二值图像。请注意,使用过滤器的内核大小会改变您需要使用的阈值级别。试用它以查看输出变化。
然后反转图像并应用regionprops
检测图像中的物体。之后用一点数学推导出 x 和 y 原点(定义左上角)以及包含图像中所有字母的大边界框的宽度和长度。
代码如下:
clear
clc
close all
Im = rgb2gray(imread('Imtext.png'));
%// Apply median filter to remove outliers
Im = medfilt2(Im,[9 9]);
%// Clear borders and apply threshold, then invert image
ImBW = imclearborder(~(im2bw(Im,.55)));
%// Find bounding boxes to delineate text regions.
S = regionprops(ImBW,'BoundingBox');
%// Concatenate all bounding boxes and obtain x,y, width and length of big
%// bounding box enclosing everything
bb = cat(1,S.BoundingBox);
LargeBB_x = min(bb(:,1));
LargeBB_y = min(bb(:,2));
LargeBB_height = max(bb(:,4));
%// Find last column in which pixel value is 1; that's the end
%// of the bounding box.
[~,ic] = find(ImBW==1);
MaxCol = max(ic(:));
LargeBB_width = MaxCol-LargeBB_x;
%// Display boxes
imshow(ImBW)
hold on
rectangle('Position',[LargeBB_x LargeBB_y LargeBB_width LargeBB_height],'EdgeColor','r','LineWidth',2)
hold off
并且输出:
或用原图: