Find camera matrices for image patches - geometry

I have an image and its corresponding camera matrix(intrinsics and extrinsics). I need to chop the image in 4 or n patches. What will be the new camera matrices for each patch of the image? Or is this even possible to find?

Related

Python:Contouring around the rectangle object in a image to obtain the corner points of the rectangle

I have an image which consists of an rectangular object in it and i want to find the 4 corners of the rectangle so that i can calculate the angle of inclination of that object to rotate the image based on that angle.I wanted to know if there are ways to identify the 4 corners of rectangular object so that i can wrap the image using the calculated angle.
I have tried doing some image processing stuff such as converting it gray scale and reducing the noise through Gaussian filter and after which i detect the edge using edge detection filter followed by thresholding and finding the contour.
The problem is that the contours that are found is not consistent and its not performing well on different images from my dataset .Also the background for each of these images is not constant it varies.
Try cv.findContours() on the binarized image, with white object on black background. Then run either cv.boundingRect() or cv.minAreaRect() on the contour.
See Tutorial here: https://docs.opencv.org/3.4/dd/d49/tutorial_py_contour_features.html

Is there a way to get the hue value of an image using Python?

I am trying to build a machine learning algorithm where I need to convert pictures to their binaries. I am using Pillow library to get the data from images. Since the performance of the algorithm is not great, I need extra parameters to thoroughly train the network and one of the extra parameters might be hue.
So is there a method in Python that gives me hue value of an image?
I am not sure what you are really trying to do, as Christoph says in the comments, but you can find the mean hue of all the pixels in an image with PIL like this:
from PIL import Image, ImageStat
# Load image, convert to HSV and split the channels, retain H, discard S and V
H, _, _ = Image.open('image.png').convert('RGB').convert('HSV').split()
# Print the mean Hue across all pixels
print(ImageStat.Stat(H).mean)
Note that I converted to RGB first to avoid problems that may arise if you try this with palette images, CMYK images, images with transparency and greyscale images. See here.

How can I magnify an Image in openCV without resize

I have an image with size 75x75 pixels and I want to select a Region of Interest in this image.
The small size of the image does not allow an accurate selection of the interesting pixels using opencv.
I already have a ROI selection function using the opencv library.
Is there a way to magnify each pixel so that opencv displays each image pixel using 4 pixels of the screen? Resizing is not an option since I need the exact pixel positions of the ROI.

Does vtk mesh generation change coordinates?

I converted nifti file to vtk using python-implemented vtk. The main function was vtkMarchingCubes.
contour=vtk.vtkMarchingCubes()
The result vtk meshes have proper shape but their locations seem changed.
For example, when I load them with the pial surface made from exactly the same nifti image using different pipelines (freesurfer) in the same scene, the result is like below.
Does vtk converting of nifti changes the coordinate of vertices or somehow 'reset' them?
VTK's MarchingCubes filter should produce triangles in the same coordinate system as the volume. The only issue is that the Nifti image also includes a coordinate system of the image, and VTK is probably not correctly using it. I'd guess there's a transform in the Nifti that VTK isn't properly using.
Try using either Slicer (slicer.org) or ITK-Snap (itksnap.org). They do better at maintaining coordinate systems for medical images.
Yes, VTK changes the coordinate when read nifti.
-get Q-matrix using GetQFormMatrix()
-transform coordinate using vtkTransform()
is reqiured.

Cropping a minibatch of images in Pytorch -- each image differently

I have a tensor named input with dimensions 64x21x21. It is a minibatch of 64 images, each 21x21 pixels. I'd like to crop each image down to 11x11 pixels. So the output tensor I want would have dimensions 64x11x11.
I'd like to crop each image around a different "center pixel." The center pixels are given by a 2-dimensional long tensor named center with dimensions 64x2. For image i, center[i][0] gives the row index and center[i][1] gives the column index for the pixel that should be at the center in the output. We can assume that the center pixel is always at least 5 pixels away from the border.
Is there an efficient way to do this in pytorch (on the gpu)?
UPDATE: Let me clarify that the center tensor is formed by a deep neural network. It acts as a "hard attention mechanism," to use the reinforcement learning term for it. After I "crop" an image, that subimage becomes the input to another neural network. That's why I want to do the cropping in Pytorch: because the operations before and after the cropping are in Pytorch. I'd like to avoid having to transfer anything from the GPU back to the CPU.
I raised the question over on the pytorch forums, and got an answer there from smth. The grid_sample function should totally solve the problem.
https://discuss.pytorch.org/t/cropping-a-minibatch-of-images-each-image-a-bit-differently/12247
torchvision contains transforms including RandomCrop, but it doesn't seem to fit your use case if you want the images cropped in a specific way. I would recon that PyTorch, a deep learning framework, is not the appropriate tool for cropping images.
Instead, have a look at this tutorial that uses pillow. You should be able to implement your use case with this. Also have a look at pillow-simd which does some operations faster.

Resources