I want extract all the text from the given image.

2 Ansichten (letzte 30 Tage)
Merin
Merin am 28 Feb. 2024
Beantwortet: Pratyush Swain am 15 Mär. 2024
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
imshow(img);
imshow(BW);
% 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
imshow(imgWithText);

Antworten (1)

Pratyush Swain
Pratyush Swain am 15 Mär. 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: https://www.mathworks.com/help/vision/ug/recognize-text-using-optical-character-recognition-ocr.html.
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);
figure
% Realize the difference between the two images %
imshowpair(BW,BW2,"montage")
% Finally perform ocr to extract text %
results = ocr(BW2);
results.Text
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!

Translated by