How to remove text from an image?

9 ビュー (過去 30 日間)
Jhilam Mukherjee
Jhilam Mukherjee 2015 年 3 月 1 日
コメント済み: Image Analyst 2019 年 1 月 10 日
I am working on medical images. In most of the image contain patient details. While segmenting those images these texts are also segmented along with the region of interest. I want to remove those text from images before segmentation.

採用された回答

Image Analyst
Image Analyst 2015 年 3 月 1 日
Presumably those details are not covering up the image data you're interested in. So then you can just assign those pixels to 0 or some other intensity:
grayImage(row1:row2:col1:col2) = 0;
Of course you need to know what rows and columns contain your annotation.
  4 件のコメント
Image Analyst
Image Analyst 2017 年 6 月 17 日
Get rid of any blobs with a centroid within 10% of the edge of the image. This code works for both of your images:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 25;
%===============================================================================
% Get the name of the image the user wants to use.
% baseFileName = 'pat00002_1-1-1-1-2-10-1.mp4.cover.png';
baseFileName = '1-1-1-1-2-8-1 2.mp4.cover.png';
% Get the full filename, with path prepended.
folder = []; % Determine where demo folder is (works with all versions).
fullFileName = fullfile(folder, baseFileName);
%===============================================================================
% Read in a demo image.
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
axis on;
caption = sprintf('Original Gray Scale Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo();
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
% Binarize the image by thresholding.
mask = grayImage > 17;
% Display the mask image.
subplot(2, 2, 2);
imshow(mask);
axis on;
axis image; % Make sure image is not artificially stretched because of screen's aspect ratio.
title('Binary Image Mask', 'fontSize', fontSize);
drawnow;
% Find the areas
labeledImage = bwlabel(mask);
props = regionprops(labeledImage, 'Area', 'Centroid');
allAreas = sort([props.Area], 'descend')
allCentroids = [props.Centroid];
centroidsX = allCentroids(1:2:end);
centroidsY = allCentroids(2:2:end);
% Make a margin of 10% of the image size.
marginx = 0.1 * columns;
marginy = 0.1 * rows;
keepers = (centroidsX > marginx & centroidsX < (columns - marginx)) & ...
(centroidsY > marginy & centroidsY < (rows - marginy))
indexes = find(keepers);
% Get a mask with only the keepers in it
newMask = ismember(labeledImage, indexes);
% Display the mask image.
subplot(2, 2, 3);
imshow(newMask);
axis on;
axis image; % Make sure image is not artificially stretched because of screen's aspect ratio.
title('Binary Image Mask', 'fontSize', fontSize);
drawnow;
% Mask the gray scale image
maskedGrayImage = grayImage; % Initialize.
maskedGrayImage(~newMask) = 0;
% Display the masked grayscale image.
subplot(2, 2, 4);
imshow(maskedGrayImage);
axis on;
axis image; % Make sure image is not artificially stretched because of screen's aspect ratio.
title('Binary Image Mask', 'fontSize', fontSize);
title('Masked Gray Scale Image', 'fontSize', fontSize);
drawnow;
Imran
Imran 2019 年 1 月 10 日
I have tried this code to my image named (Original) but it still leaves some unneceassary text. Output image named (Masked). Please give me code to remove it.

サインインしてコメントする。

その他の回答 (2 件)

divya d
divya d 2018 年 12 月 4 日
Am an reserach scholar. i tried the above code to remove the unnecessary patient details from echo images. i attached the result. verify it and suggest some other code. plz repy.
  1 件のコメント
Image Analyst
Image Analyst 2018 年 12 月 4 日
Use imcrop().

サインインしてコメントする。


Imran
Imran 2019 年 1 月 10 日
I have tried your this code to my image named (Original) but it still leaves some unneceassary text. Output image named (Masked). Please give me code to remove it.
  3 件のコメント
Imran
Imran 2019 年 1 月 10 日
Actually I have shared you gray sclaed output images of Matlab. I have attached the actual RGB image. Can i remove more text as compared to image named Masked using Matlab???
Image Analyst
Image Analyst 2019 年 1 月 10 日
Actually, my answer stays unchanged. This is not the original image. You want the original image, not one with annotations imprinted on it. See if you can get the original images. They might be in dicom format which is used a lot in the medical field.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by