detect small image in large one - python

I am new to Machine learning.
I have an image with size 28x200 as above. I have to detect images of size 28x28 in the large picture of size 28x200. For example, in this large image, there are three 28x28 images. How could I detect them? I read some answers using OpenCV but I could not manage to make it work with numpy array (.npy file), the answers are mainly concerned with JPG. Any solutions? Thanks in advance!

Related

PIL ImageOps equalize function damages the image pixels

I am working on a mammography dataset and while trying different filters that might help the model to learn better, I came across this error.
(images are screenshots from the mammography images because it is a private dataset!)
PIL.ImageOps.equalize() function distort the image from left to right.
How to prevent the function to mess the image?
Or how can I pick images that may cause this problem before give them to model in preprocess stage( What kind of operation or function may help to split this image from others)?

Compressing PIL image without saving the file

I am having trouble with compressing image in python without saving the image at the disk. The image has a save function as described here. Here it optimizes the image by saving it. Is it possible to use the same procedure without saving the image. I want to do it like another python function.
image=image.quantize() [here it reduces the quality a lot ]
Thanks in advance :)
In PIL or opencv the image is just a large matrix with values for its pixels. If you want to do something with the image(e.g. display it), the function needs to know all the pixel values, and thus needs the extracted image.
However, there is a method to keep the image compressed in memory until you really need to do something with the image. Have a look at this answer: How can i load a image in Python, but keep it compressed?

Converting a 12-bit grayscale image to 8-bit per channel color image in Python

I am looking for suggestions or best practices to follow in terms of converting a 12-bit (0-4096) grayscale image to a 3-channel 8-bit color image in Python in order to pass it into a convolutional neural network.
With 8-bit RGB, I essentially have 24-bit colour, so I see no reason to lose data in the conversion, although most other posts suggest simply dividing the pixel value by 16 in order to squeeze it into 8-bits and then replicating this over all three channels in a lossy way.
Some ideas I have come up with include creating some kind of gradient function that converts the 12-bit uint to a corresponding colour on the gradient, but my understanding of the RGB colour space is that this would be tricky to implement using Numpy or other such libraries.
Do any of the common libraries such as OpenCV / Scikit offer this kind of functionality? I cannot find anything in the docs. Other ideas include using some kind of intermediary color space such as HSL/L*AB but I don't really know enough about this.
Please note that I am ultimately trying to create an 8-bit RGB image, not a 16-bit RGB image. Simply trying to colorize the grayscale image in a way that retains the original 12-bit data across the colour range.
Hope somebody can help!
My first question would be: Why do you need to convert it to color in any specific way?
If you are training the CNN on these images, any arbitrary transformation should work and give you similar performance. You just need to convert the training images and input images in the same manner.
You could probably just split the 16 bits and put the bottom half in R, the top half in G, and leave B with zeroes.
It kinda depends on how black-box this CNN is. But you can always test this by running a few training/testing cycles with the conversion I mentioned above and then do that again with the "compressed" versions.

divide image without loosing its coordinates (tile)

I have a large images 5000x3500 and I want to divide it into small images 512x512 but without loosing the original image coordinates. The large images are annotated/labled that's why I want to keep the original coordinates and I will use the small images to train YOLO model. I am not sure if that called tiled or not. but is there any suggestion to do it using python or opencv-python?

Decompose a Image into its character images

I am very new to image processing and try to build a OCR for specific font using opencv and Python.
I am able to reduce the image below:
to this:
I have already written a small neural network to deduce character images into its respective English characters. Can someone help me to crop the cropped B/W image further into small images with just the characters?
The one way I could think of is by moving pixel by pixel and stop when a black pixel occurs. Is there any other way?
I think you should try cv::blobDetector
https://www.learnopencv.com/blob-detection-using-opencv-python-c/
Or just cv::findcountours with CV_EXTERNAL flag:
http://docs.opencv.org/3.1.0/df/d0d/tutorial_find_contours.html

Categories