# Extract data from jpg images

**URL:** <https://forum.knime.com/t/extract-data-from-jpg-images/57999>\
**Category:** KNIME Analytics Platform\
**Created:** [January 2, 2023, 5:49pm UTC](https://forum.knime.com/t/extract-data-from-jpg-images/57999 "2023-01-02T17:49:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnthonyCREng](https://forum-cdn.knime.com/user_avatar/forum.knime.com/anthonycreng/32/24358_2.png) [@AnthonyCREng](https://forum.knime.com/u/AnthonyCREng)\
**Post date:** [January 2, 2023, 5:49pm UTC](https://forum.knime.com/t/extract-data-from-jpg-images/57999/1 "2023-01-02T17:49:26Z")

</div>

Hi Knime Community, happy new year! 🙂

Would like to know how can I extract data from jpg images.

I will appreciate your kind commentaries and suggestions.

---

<div class="post-metadata">

**Author:** ![qqilihq](https://forum-cdn.knime.com/user_avatar/forum.knime.com/qqilihq/32/50_2.png) [@qqilihq](https://forum.knime.com/u/qqilihq)\
**Post date:** [January 2, 2023, 6:22pm UTC](https://forum.knime.com/t/extract-data-from-jpg-images/57999/2 "2023-01-02T18:22:33Z")

</div>

Happy 2023!

What kind of data do you need to extract?

–Philipp

---

<div class="post-metadata">

**Author:** ![AnthonyCREng](https://forum-cdn.knime.com/user_avatar/forum.knime.com/anthonycreng/32/24358_2.png) [@AnthonyCREng](https://forum.knime.com/u/AnthonyCREng)\
**Post date:** [January 2, 2023, 6:49pm UTC](https://forum.knime.com/t/extract-data-from-jpg-images/57999/3 "2023-01-02T18:49:06Z")

</div>

Hi qqlihq, thanks for your prompt response.

Well I got 5 screenshots which contain diverse financial data distributed in not specific order across those images.

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [January 2, 2023, 7:35pm UTC](https://forum.knime.com/t/extract-data-from-jpg-images/57999/4 "2023-01-02T19:35:22Z")

</div>

@AnthonyCREng here are two examples using R packages to extract text and tables from PDF files. Maybe you can give us some examples of what you want to extract so there might be solutions either with KNIME (parsers) or R or Python.

> [@Text mining from PDF documents and results places](https://forum.knime.com/t/text-mining-from-pdf-documents-and-results-places/48186/3):
>
> @janszky_nav I adapted an older example ([How to read multiple lines from PDF File - #6 by mlauber71](https://forum.knime.com/t/how-to-read-multiple-lines-from-pdf-file/46510/6)) using R code to extract the text from PDF files and then search for the page and line where a special word (in this case “Procter”) would appear.

> [@How to read multiple lines from PDF File](https://forum.knime.com/t/how-to-read-multiple-lines-from-pdf-file/46510/6):
>
> @Subramanyam you could try and use the [R package pdftools](https://www.r-bloggers.com/2021/06/extract-text-from-pdf-in-r-and-word-detection/) to extract the text. It will also extract the content of the table but there might be better ways to deal with them as we already have discussed - [Solutions to "Just KNIME It!" Challenge 15](https://forum.knime.com/t/solutions-to-just-knime-it-challenge-15/42482), [Extract Table from PDF with the help of R "tabulizer" and KNIME – KNIME Hub](https://kni.me/w/3YMQ5EiC7ojFR7AZ)). Every page will be in a table row so you might take it from there and start splitting and manipulating the header in order to get your information. [kn\_example\_…](https://forum.knime.com/uploads/short-url/oR0TgYDfOAGwyBeyf65UJ1iHSsu.knwf)

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [January 2, 2023, 9:02pm UTC](https://forum.knime.com/t/extract-data-from-jpg-images/57999/5 "2023-01-02T21:02:44Z")

</div>

@AnthonyCREng I put this task to [ChatGPT](https://chat.openai.com/chat#) and this is the quick result after some small tweaking …

 ![image1](https://forum-cdn.knime.com/uploads/default/original/3X/8/3/83d43bc5743819ae9d36c9e080a5becdcb092b72.png)

```auto
# you will have to install tesseract. On MacOS this would look like this:
# brew install tesseract

import cv2 # opencv
import pytesseract # pytesseract
import pandas as pd

# Read the image file
image = cv2.imread('image1.png')

# Convert the image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Apply Otsu's thresholding
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]

# Run Tesseract OCR on the image
text = pytesseract.image_to_string(thresh)

# Split the text by new line characters
lines = text.split('\n')

# Create a dataframe from the lines
df = pd.DataFrame([x.split() for x in lines])

# Print the dataframe
print(df)

# export the file to excel
df.to_excel('image1.xlsx', index=True, sheet_name='Sheet1')

```

This is the result you could then further use:

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/7/8/7887512037ccdeccaca63be719d458c1f72e5984.png)

[image1.xlsx](https://forum.knime.com/uploads/short-url/kc4vGFmcyREDS39SyX6brrx2SNK.xlsx) (5.8 KB)

Will have to turn this into a KNIME workflow, maybe tomorrow 🙂

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [April 2, 2023, 9:03pm UTC](https://forum.knime.com/t/extract-data-from-jpg-images/57999/6 "2023-04-02T21:03:15Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
