How to change a part of the color of the background, which is black, to white? - python-3.x

I have been working on PyTesseract OCR and converting PDF to JPEG inorder to OCR the image. A part of the image has a black background and white text, which Tesseract is unable to identify, whereas all other parts of my image are being read perfectly well. Is there a way to change a part of the image that has black background? I tried a few SO resources, but doesn't seem to help.
I am using Python 3, Open CV version 4 and PyTesseract

opencv has a bitwise not function wich correctly reverses the image
you can put a mask / freeze on the rest of the image (the part that is correct already) and use something like this:
imageWithMask = cv2.bitwise_not(imageWithMask)
alternatively you can also perform the operation on a copy of the image and only copy over parts / pixels / regions you need....

Related

How to extract background image and text from a image

I have an image and am trying to separate the background image and text.
For text I have used pytesseract and it gives me all the data. Now my aim is to translate this text and place it back on the image.
For that I need the background image and the position of the text where I need to put the text back.
I need some help or pointers as I have been trying to use OpenCV for same but no luck yet.
Thanks
-Megha

Method to remove color artifacts on stills from DV tapes

I'm trying to use optical character recognition (OCR) to read text printed on digital video (DV) tapes. I'm using cropped still frames from the video for the OCR process. The text is white, but there are color artifacts (maybe composite color artifacts) so that the white text has color bleeding onto it (see example below). The colors look to be in magenta-cyan-yellow colorspace, maybe?
OCR results would likely be improved if I could remove/filter those colors to leave only white on the text. Then I can create a binary black/white image. I can do this now, but I suspect results will improve if I can remove colors from the white text before OCR, and this will hopefully help separate the white text from the background image.
Are there any ways, using Imagemagick preferably, to filter out those colors from the white text? I'm not sure of the best way to approach this since there are multiple colors bleeding, and the background changes in each frame. Currently using Imagemagick version 6.9.2-3 Q16 x64 on Windows 7.
Sample full-frame image:
Sample of cropped region with text (note color-bleed and white text blending into background):
I would suggest leveraging ImageMagick's FX & Morphology Dilate to preprocess the image. But to be honest, it'll take a bit of trial & error to find the solution that would work for you. I would also recommend that whatever solution you develop allows graceful error handling (i.e. If attempted OCR process unsuccessful, emit warning, and progress video to next I-frame & repeat.)
Fx Preprocessing
The -fx operator will allow you to create user-defined mathematical expression. Some quick google search about chrome-keys, and other tolerance methods might be helpful. But for many OCR techniques, it's usually common to reduce the colors to a "uniformed" gray scale.
convert aaA7b.png -fx 'intensity' intensity.png
Morphology Preprocessing
Morphology allows common & custom kernels to alter surrounding pixels. As video scanlines + other artifacts are distorting the text, I would recommend exploring Dilate, but there are many other techniques listed in the Usage documents.
Diamond
convert aaA7b.png -fx 'intensity' \
-morphology Dilate Diamond:1 diamond.png
Square
convert aaA7b.png -fx 'intensity' \
-morphology Dilate Square:1 square.png
Plus
convert aaA7b.png -fx 'intensity' \
-morphology Dilate Plus:1 plus.png
Custom
And if you need something more exact, create your own kernel by supplying the following format size: row1 row2 ... rowN. In this example, I'm creating a 3x3 kernel with a single vertical line to offset the video scanlines.
convert aaA7b.png -fx 'intensity' \
-morphology Dilate \
'3x3: nan,1,nan nan,1,nan nan,1,nan' user_defined.png
But YMMV. Also take a look at Fred's TextCleaner script. The -deskew & -sharpen operators will help reduce the noise.
Sample of cropped region with text (note color-bleed and white text blending into background):
I think there's a saying "You can't make steak from a hamburger." or something like that. At some point the background will washout the text in the foreground, and it's time better spent to create a solution that acknowledges this.

Landmasking in SAR geotiff image

I am trying to mask the land in a satellite (SAR) grayscale geotiff image. The functionality is available in rsgislib, but it works on Linux and I am working on conda python 3.5 (Windows) and not able to find a possible way out.
Kindly guide as to how the land can be masked out in an image.
I found the way out :
First we have to download an appropriate shapefile of the region we wish to mask,
then there is a beautiful functionality available in gdal called as gdalwarp. We need to just open the anaconda prompt and from there just type in :`
gdalwarp -cutline shapefile_name.shp original_image.tif output_filename.tif
Now, the image with borderlines of the land will get saved in the file output_filename.tif
This is the file which contains the land portion and the ocean is masked out.
Then the procedure becomes fairly simple mask out the land by subtracting the output_filename.tif image from original image.
We will get the image of the ocean part with land portion in black, after that we can make the land portion as NaN.

Create an Image either using Magick Wand or ImageMagick on Python 3

There's not enough information on Internet about imagemagick and magick wand on Python 3. I need to create a lot of images using Python 3, creating the images with a background color or a background image.
When I get the image with the background I want, then I need to add text with a font of my preference on It, I think I can solve the problem of the font, but how to add the "string" in the image?
After that, I want to save the image with a "name".
I have installed Magick wand and Image Magick on Python 3, but the documentation is in a language that I really don't understand. Do I need to install something else?
If you're able to help me, it would be great. Thank you!
You can achieve these using Wand.
Creating the images with a background color or a background image
Add text with a font
Save the image with a “name”

converting rgb image to gray image in vc++ using opencv

i created gui application in vc++2010 express, i loaded image folder to list box and by selecting listbox item the image is displaying in picturebox1, using browse button.
Now i want to access the picturebox1 image and convert to gray scale image and converted grey scale must be displayed in picturebox2, using grey convert button. plzz help me frnds
thanq
karuna
Get the image in opencv Mat. Then use cvtColor function to convert the image. CV_BGR2GRAY code is used to convert from RGB to grayscale. Then show the grayscale image back to wherever you want to display it.

Resources