Image Super-resolution by Radial Basis Functions - python

In this project, you will implement the image super-resolution problem. Specifically,
you will start from a digital image of size M*N pixels, and then you will enlarge the
image to (3M) * (3N) pixels. While the pixels in the original image should keep their
original intensities, the intensities of new pixels are interpolated by using a local radial
basis function in a user-chosen neighborhood of each new pixel.
This is the image I want to enlarge.
The image is 256 x 256. I want to use Colab and I found a function pysteps.utils.interpolate.rbfinterp2d and here is the documentation for this function:
https://pysteps.readthedocs.io/en/latest/generated/pysteps.utils.interpolate.rbfinterp2d.html.
I am very new to computer programming and I am wondering how do I actually do this. I can do individual steps, so I am more or less looking for a (detailed, if possible) outline of steps to accomplish the task. At the end of the project I want to display the original image and then the resulting image after up-scaling it.
Any help would be much appreciated. Thanks in advance!

Related

Promblem to use iradon on image with the shape of (168,400)

I want to implement iradon. Radon image shape is (168,400).
But when I implement iradon on it the image shape become (168,168)!!!
I want to have an image with (168,400) shape.
Where is the problem?
Image = iradon (radon_image, filter_name=None)
I read the instruction on:
https://scikit-image.org/docs/stable/api/skimage.transform.html#skimage.transform.iradon
; but I did not understand the problem.
I really appreciate if anyone can help me.
I think you might be mis-understanding how the Radon (and inverse Radon) transform work.
The size of your radon_image is (number of pixels in original image, number of projections). So in your example, the image is 168 pixels across with 400 different projections (see image below from the scikit-image website). Therefore, when you perform the inverse Radon transform you will get an image with a size of 168 pixels.
Perhaps if you explain further why you want the resulting image with a particular size, it will be possible to help further.

How to resize image without losing pixel qualityin python?

I have an 32x32 image. I resize it for 512x512 in python, quality and view of image is not same when I resize it in paint.
original image resized-with-paint resized-with-python
What is needed to add to have same result as Paint?
from PIL import Image
im=Image.open('1.png')
im=im.resize(512,512)
im.save('resized.png')
Use:
im = im.resize((521,512), resample=Image.NEAREST)
for that effect.
It is not really a "loss of quality" that you are seeing - it is actually a difference in the interpolation method. When upsizing an image, the algorithm effectively has to "invent" new pixels to fill the bitmap raster. Some algorithms interpolate between known surrounding values, other algorithms just take the closest value - also known as "Nearest Neighbour". There are both advantages and disadvantages - "Nearest Neighbour" will be faster and will not introduce new "in-between" colours into your resized image. On the downside, it will be slower, look more "blocky" and less smooth.
It requires some thought and experience to choose the appropriate method.

How does the Image Registration/alignment and transformation work on the pixel level?

I know the basic flow or process of the Image Registration/Alignment but what happens at the pixel level when 2 images are registered/aligned i.e. similar pixels of moving image which is transformed to the fixed image are kept intact but what happens to the pixels which are not matched, are they averaged or something else?
And how the correct transformation technique is estimated i.e. how will I know that whether to apply translation, scaling, rotation, etc and how much(i.e. what value of degrees for rotation, values for translation, etc.) to apply?
Also, in the initial step how the similar pixel values are identified and matched?
I've implemented the python code given in https://simpleitk.readthedocs.io/en/master/Examples/ImageRegistrationMethod1/Documentation.html
Input images are of prostate MRI scans:
Fixed Image Moving Image Output Image Console output
The difference can be seen in the output image on the top right and top left. But I can't interpret the console output and how the things actually work internally.
It'll be very helpful if I get a deep explanation of this thing. Thank you.
A transformation is applied to all pixels. You might be confusing rigid transformations, which will only translate, rotate and scale your moving image to match the fixed image, with elastic transformations, which will also allow some morphing of the moving image.
Any pixel that a transformation cannot place in the fixed image is interpolated from the pixels that it is able to place, though a registration is not really intelligent.
What it attempts to do is simply reduce a cost function, where a high cost is associated with a large difference and a low cost is associated with a small difference. Cost functions can be intensity based (pixel values) or feature based (shapes). It will (semi-)randomly shift the image around untill a preset criteria is met, generally a maximum amount of iterations.
What that might look like can be seen in the following gif:
http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/registration_visualization.gif

OpenCV how to replace cut out object with background

I have two images, one image which contains a box and one without. There is a small vertical disparity between the two pictures since the camera was not at the same spot and was translated a bit. I want to cut out the box and replace the hole with the information from the other picture.
I want to achieve something like this (a slide from a computer vision course)
I thought about using the cv2.createBackgroundSubtractorMOG2() method, but it does not seem to work with only 2 pictures.
Simply subtracting the picture from another does not work either because of the disparity.
The course suggests using RANSAC to compute the most likely relationship between two pictures and subtract the area thaht changed a lot. But how do I actually fill in the holes?
Many thanks in advance!!
If you plant ot use only a pair of images (or only a few images), image stitching methods are better than background subtraction.
The steps are:
Calculate homography between the two images.
Warp the second image to overlap the second.
Replace the region with the human with pixels from the warped image.
This link shows a basic example of image stitching. You will need extra work if both images have humans in different places, but otherwise it should not be hard to tweak this code.
You can try this library for background subtraction issues. https://github.com/andrewssobral/bgslibrary
there is python wrappers of this tool.

Problems understand preprocessing steps that turn images into the format of MNIST dataset

I want to make a program that turns a given image into the format of the MNIST dataset, as a kind of exercise to understand the various preprocessing steps involved. But the description the authors made on their site: http://yann.lecun.com/exdb/mnist/ was not entirely straightforward:
The original black and white (bilevel) images from NIST were size
normalized to fit in a 20x20 pixel box while preserving their aspect
ratio. The resulting images contain grey levels as a result of the
anti-aliasing technique used by the normalization algorithm. the
images were centered in a 28x28 image by computing the center of mass
of the pixels, and translating the image so as to position this point
at the center of the 28x28 field.
So from the original I have to normalize it to fit a 20x20 box, and still preserving their aspect ratio (I think they mean the aspect ratio of the actual digit, not the entire image). Still I really don't know how to do this.
Center of mass: I have found some online code about this, but I don't think I understand the principle. Here is my take on this: The coordinate of each pixel is actually a vector from the origin to that point, so for each point you multiply the coordinate with the image intensity, then sum everything, before dividing by the total intensity of the image. I may be wrong about this :(
Translating the image so as to position this point at the center: Maybe cook up some translation equation, or maybe use a convolutional filter to facilitate translation, then find a path that leads to the center (Dijikstra's shortest path ?).
All in all, I think i still need guidance on this. Can anyone explain about these parts for me ? Thank you very much.
I think

Categories