How to load diverse images with `tf.train.string_input_prodecer()` in tensorflow? - tensorflow

I get an image set full of images with different sizes and extensions. Most of their colorspaces is RGB while some got the extra alpha channel.
How can I convert them to 227*227*3 (3 means RGB) in tensorflow?
Thanks a lot!

Have a look at the Image APIs
In particular, what would be of interest to you is perhaps the following functions in the Cropping header:
tf.image.resize_image_with_crop_or_pad
tf.image.central_crop
tf.image.pad_to_bounding_box
tf.image.crop_to_bounding_box
tf.image.extract_glimpse
tf.image.crop_and_resize
As for the Alpha channel, it really depends on how you are reading in the images. If you are using tf.image.decode_image, you can perhaps try specifying channels=3/4 (I'm not sure if this will break the code) but if it's like what you mentioned, some pictures have alpha and some don't, then you might want to use cv2 or PIL to entirely preprocess the images and crop them to 227x227x3.

Related

TensorFlow find and mark multiple image boundaries

My example is that I have an image with 5 other images on it. Whats the best way to have TensorFlow find/calculate the bounding boxes for each of those... need to take into account that in other images there might only be 3 separate images.
I've found that if I run a cv2.Laplacian on the source image it nicely outlines the 5 individual images but I'm not sure how best to use tensorflow to detect each of those bounding boxes?
UPDATE: My ONE issue is how do I use tensorflow to find each images boundaries? obviously I can find the 4 corners of the whole image but that doesn't help me - I need it to first know how many images their are and then find each of those boundaries.

Auto crop to objects with ImageFlow.NET

Are there any plugins for ImageFlow.NET that enables me to auto crop images to focus on objects, not faces, in them? Or any other non-plugin way to do it with ImageFlow.NET?
Not yet, but it is something we're planning to add. In the meantime, you could try using https://github.com/softawaregmbh/smartcrop.net to get the crop coordinates then feeding them to Imageflow. It looks like a slow library, and the built-in encoding and resizing is very poor, but if you only use it to get coordinates you should be fine.

matplotib: two overlaid transparent images look different when saved as svg or png

I'm trying to overlay two transparent images with matplotlib and save the result, but the result looks different depending on the file type. Specifically it's much more washed-out when saving to svg.
Here's an example. In this case, I could just add the two images before displaying them, but this is just a simple example. In reality what I'm trying to do is more complicated (images of different sizes with different colormaps), so they have to be plotted separately.
Example code:
f, ax = plt.subplots(figsize=(2,2))
ax.imshow(np.eye(3), alpha=.5)
ax.imshow(np.eye(3)[::-1], alpha=.5)
f.savefig('example.png')
f.savefig('example.svg')
The png file looks just like it does on the screen, but the svg file looks washed out. I would like to know how to save as svg, without the washed-out effect (i.e. it should look like it does on the screen).
As a bonus question, why does the png plot appear different depending on the order in which I plot the transparent images? The second image always looks stronger. Interestingly, in the svg, both are equally washed out.
Example saved as png:
Example saved as svg:
matplotlib version: 3.1.3
python version: 3.7.7
Thanks for any tips!
I'll post what I think is going on, but if someone can answer with more legit information I'll accept it.
I think that every time you call imshow with an alpha value, it blends the current image in the axis with the new image, using (new * alpha + current * (1-alpha)). The problem with this is that if you display 10 images each with alpha 0.5, then the first image is attenuated to nothing by the iterative blending, whereas the last image gets to be 50% of the final result. Nonetheless this is apparently the method used for rendering to the screen and saving to png.
In contrast, when saving to svg, it saves each image as a separate overlay with its own alpha. The svg container or renderer then uses some more intelligent method that considers all overlaid images at once. However, in my particular case, this leads to a more washed-out look because all the images are partially transparent.

How a robust background removal is implemented?

I found that a deep-learning-based method (e.g., 1) is much more robust than a non-deep-learning-based method (e.g., 2, using OpenCV).
https://www.remove.bg
How do I remove the background from this kind of image?
In the OpenCV example, Canny is used to detect the edges. But this step can be very sensitive to the image. The contour detection may end up with wrong contours. It is also difficult to determine which contours should be kept.
How a robust deep-learning method is implemented? Is any good example code? Thanks.
For that to work you need to use Unet. You can search for that on github.
Unet transofrm is: I->I.
Space of the image will become image (of same or similar size).
You need to have say 10.000 images with bg removed. People, (long hair people), cats, cars, shoes, T-shirts, etc.
So you set different backgrounds on all these images as source and prediction should be images with removed background.
You can also do a segmentation model and when you find the foreground you can remove the bg.

Resize images for object detection

I want to train images with mask RCNN and my understanding is that all the images need to be the same size. I also read that you can add "padding" to images so that you can retain the right aspect ration.
Does anyone know how to add padding to the images and resize?Does anyone have a code for that or an online tool which can do that?
Thanks
In opencv library, there are padding function that can add borders to your images.
also, resize function too.
refer to this webpage.