Hi Friend's..

M new to c#.net can anyone say How to Count number of liens and Characters in a Tiff image ....


T ks in Adv...

G.Sam...

Dani AI

Generated

For : the TIFF file itself is pixels, so you need OCR to turn those pixels into text before you can count "lines" or "characters" (this expands on what and observed). A practical workflow that works for scanned text:

  • Preprocess the image: increase DPI to ~300, convert to grayscale, apply a threshold or denoise and deskew. Better preprocessing → better OCR.
  • Run an OCR engine page-by-page (single-page TIFFs are straightforward; multi-page TIFFs require iterating frames).
  • Count lines and characters from the OCR output. For simple needs, split on newline characters; for more accurate physical line counts use the OCR engine's layout iterator.

Minimal C# example using the Tesseract .NET wrapper (single page). It extracts text, counts non-empty lines and characters excluding newline characters:

using System;
using Tesseract;

string tessData = @"./tessdata"; // path to traineddata
string file = "input.tif";

using (var engine = new TesseractEngine(tessData, "eng", EngineMode.Default))
using (var img = Pix.LoadFromFile(file))
using (var page = engine.Process(img))
{
    var text = page.GetText() ?? string.Empty;
    var lines = text.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
    int lineCount = lines.Length;
    int charCount = text.Replace("\r", "").Replace("\n", "").Length;
    Console.WriteLine($"Lines: {lineCount}  Characters (no newlines): {charCount}");
}

Notes and troubleshooting:

  • For multi-page TIFFs, extract frames (for example with Magick.NET) and run the same OCR per frame.
  • If line breaks are inconsistent, use the OCR engine's layout iterator (page iterator) to count recognized text lines rather than splitting text.
  • Poor scans, handwriting, low DPI or complex layouts reduce accuracy. For high-volume or mission-critical tasks consider commercial SDKs (ABBYY, LEADTOOLS, IronOCR) if Tesseract results are insufficient.

Tesseract .NET wrapper: https://github.com/charlesw/tesseract
Magick.NET (for multi-page/frame handling and preprocessing): https://github.com/dlemstra/Magick.NET

Recommended Answers

All 6 Replies

As Sknake answered in the other post, if you need the tiff OCR'd then you need a package. If you need to know the number of bytes, then just open the file in a FileStream (or a number of other classes), and check the length.
If not OCR'd, then you are working with the raw image which is in bytes not lines or chars.

Tks Jerry Shaw ....

Is There is any possible way to segment text in the given (text tiff image):S ....

Yes, buy an OCR library. You can keep rephrasing the same question but you will keep getting the same answer.

The same goes for opening up another thread with the same issue.

Tk u Frnd....


Can u say any Sample code project for that OCR to Segment the text in the image....


Tks in Adv..

G.Sam....

Yes, when you purchase an OCR suite it comes with sample projects. If I post sample code and you don't have the OCR library then it does you no good.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.