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.

조회 수: 10 (최근 30일)
i plan to extract the marked text..please provide the code

채택된 답변

Image Analyst
Image Analyst 2014년 1월 25일
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);
uiwait(warndlg(errorMessage));
return;
end
end
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);
imshow(rgbImage);
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);
imshow(binaryImage);
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);
imshow(binaryImage);
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);
imshow(thisCroppedImage);
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')
return;
end
end
  댓글 수: 10
ANAND SARIT
ANAND SARIT 2014년 2월 3일
thank you so much.. the older algorithm is working perfectly on png images...and the new one works on jpeg images..thank u very much....

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Bruno Pop-Stefanov
Bruno Pop-Stefanov 2014년 1월 22일
편집: Bruno Pop-Stefanov 2014년 1월 22일
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;
  댓글 수: 4
Sony s
Sony s 2017년 10월 30일
please let me know what will be the values of hueThresholdLow, hueThresholdHigh , saturationThresholdLow , saturationThresholdHigh , valueThresholdLow, valueThresholdHigh , these parameters for brown color, black color magenda color
Image Analyst
Image Analyst 2017년 10월 30일
Depends on your image. See the Color Thresholder app on the Apps tab of the tool ribbon.

댓글을 달려면 로그인하십시오.


ANAND SARIT
ANAND SARIT 2014년 1월 24일
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...
  댓글 수: 2
Image Analyst
Image Analyst 2014년 1월 24일
편집: Image Analyst 2014년 1월 24일
Not sure what you mean? Do you want the bounding box of the yellow regions cropped out into separate images? Just like the original (black text on yellow background), but cropped? If the yellow "Pure" yellow, in other words, r=255, G=255, and B = 0?
ANAND SARIT
ANAND SARIT 2014년 1월 25일
yes that is what i exactly want.. can you please provide me the code... thank u very much...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by