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.
8 次查看(过去 30 天)
显示 更早的评论
i plan to extract the marked text..please provide the code
0 个评论
采纳的回答
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
更多回答(2 个)
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:
- Take a look at tutorials that Image Analyst has written on the File Exchange.
- Convert the image into HSV space and manually define thresholds around the yellow highlight color to extract yellow pixels.
- Take a look at a tutorial here.
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
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
2017-10-30
Depends on your image. See the Color Thresholder app on the Apps tab of the tool ribbon.
ANAND SARIT
2014-1-24
2 个评论
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?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!