Clear Filters
Clear Filters

I want extract all the text from the given image.

5 views (last 30 days)
I am trying to extract the numbers from this image along with its name (FiO2, Pmean, PEEP, etc.). I am using the below code to extract it using the color thresholder app. I am facing 2 problems. Using the color thresholder app i am only able to isolate the blue text (numbers) so the varibale names are getting erased. Secondly, among the blue numbers, I am getting an irrelevant text (GRY) instead of 5.0. What is going wrong?
img: original image
BW: exported image from color thresholder
% Define the path to your image
imagePath = 'thumbnail_6.jpg';
% Read the image
img = imread(imagePath);
% Display the original image to ensure it's loaded
% Perform OCR on the binary image
results = ocr(BW);
% Set text properties
text = results.Text; % Text to be inserted
position = [500, 100]; % Position of the text
fontColor = 'black'; % Color of the font
fontSize = 34; % Font size
% Insert the text into the image
imgWithText = insertText(img, position, text, 'TextColor', fontColor, 'FontSize', fontSize);
% Display the image with text

Answers (1)

Pratyush Swain
Pratyush Swain on 15 Mar 2024
Hi Merin,
I understand you utilized an image from the color thresholder app and performed ocr to extract text but did not get satisfactory results. Some steps that can be of help is further pre-processing of the input image before performing ocr to make sure the algorithm could read text properly.
You can refer to this page to know about image preprocessing techniques such as "morphological reconstruction","noise & background removal" , etc to improve ocr results:
Also another important point to note is OCR works best for an image containing dark text on a light background, so make sure to invert the binary image after exporting from color thresholding app & performing pre-processing steps:
% Assumin BW is binary image exported from app %
% Perform Preprocessing steps ..... %
% Invert clean binarized image %
BW2 = imcomplement(BW);
% Realize the difference between the two images %
% Finally perform ocr to extract text %
results = ocr(BW2);
Also you can use the following text detection algorithms use local image features to locate or segment text within an image.
Hope this helps.

Community Treasure Hunt

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

Start Hunting!