i want to extract fluorescent marked text from an image and convert the extracted image to another image file. how do i do that? i am new to matlab.

5 views (last 30 days)
i plan to extract the marked text..please provide the code

Accepted Answer

Image Analyst
Image Analyst on 25 Jan 2014
Anand: Here, I did it for you.
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 = 20;
% Read in a color image.
folder = 'C:\Users\anand\Documents\Temporary';
baseFileName = 'anand.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 1);
axis on;
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
binaryImage = redChannel == 255 & greenChannel == 255 & blueChannel == 0;
% Display the image.
subplot(2, 2, 2);
axis on;
title('Binary Image', 'FontSize', fontSize);
% There seem to be thin lines running through the image
% that break it up into ways we don't want.
% Dilate the image to fill the gaps.
binaryImage = imdilate(binaryImage, true(3));
% Fill the image
binaryImage = imfill(binaryImage, 'holes');
% Display the image.
subplot(2, 2, 3);
axis on;
title('Filled Binary Image', 'FontSize', fontSize);
% Label the image
[labeledImage, numberOfBlobs] = bwlabel(binaryImage);
% Measure the image
measurements = regionprops(labeledImage, 'BoundingBox');
% Display them
subplot(2, 2, 4);
for k = 1 : numberOfBlobs
thisBB = measurements(k).BoundingBox
thisCroppedImage = imcrop(rgbImage, thisBB);
axis on;
caption = sprintf('Region #%d out of %d', k, numberOfBlobs);
title(caption, 'FontSize', fontSize);
% Ask user if they want to continue;
promptMessage = sprintf('This is region #%d out of %d.\nDo you want to Continue processing,\nor Cancel to abort processing?',...
k, numberOfBlobs);
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')

Sign in to comment.

More Answers (2)

Bruno Pop-Stefanov
Bruno Pop-Stefanov on 22 Jan 2014
Edited: Bruno Pop-Stefanov on 22 Jan 2014
1. Use a color segmentation algorithm to generate a mask where white pixels correspond to the yellow highlights in your input image. To do that you can:
2. Once you have a binary mask, fill the holes left by back letters using imfill. That will give you solid blocks of white pixels on a black background.
3. "Crop" the highlighted text from your input image using that mask. The mask will be a black and white image with 1 channel, but your input image is RGB (3 channels). You can execute the following to perform that operation:
% First, convert B&W mask to RGB
% mask_bw has size (n x m x 1)
% mask_rgb will have size (n x m x 3)
mask_rgb = repmat(mask_bw,1,1,3);
% Then, the mask indicates the location of pixels in your ROI
% Use it to change the color of other pixels to white
% in_img is your input image and has size (n x m x 3)
out_img = in_img;
out_img(~mask_rgb) = 1;

Sign in to comment.

ANAND SARIT on 24 Jan 2014
Thanks a lot.. but i have one problem.. after it the highlighted text is only shown, i want to crop all the individually highlighted text and paste it into another file.. for example, in this portion there are two paragraphs of highlighted text.. i want to crop those parts only and paste these two paragraphs in another file.. can u help me,please? thanks a lot...

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by