How to resize sparse LiDAR depth label? - python-imaging-library

I have created depth label using LiDAR point cloud. Originally, the labels are of size 1536 X 1536. All pixels where LiDAR points are projected contains depth values and remaining values are filled with NANs. See mask_from_original_depth_label . And I want to resize these labels to size 512 X 512 without aliasing.
I am using PIL to resize them, however all interpolations except for nearest neighbor fails. And with nearest neighbor interpolation, it appears that the labels have aliasing. See mask_from_resized_image . How should I resize these labels without causing an aliasing. Any hints would be appreciated.

Related

how to find lowest vertical and horizontal DCT coefficient of an image block

I have an image of size 256x256 and it is divided into equal non overlapping blocks of size 8x8. I have to find the lowest vertical and horizontal DCT (Discrete Cosine Transform)coefficients of each image block. Is there any method available for this problem in MATLAB?
The usual method is to create an array of indices that maps from the most important to the least important as you have stored them.
This is the pattern used in JPEG. What we don't know is how you have arranged your coefficients so we cannot give you the ordering.

Disparity calculation of two similar images in matlab

I have two images(both are exactly same images) and I am trying to calculate the disparity between them using sum of squared distances and reconstruct disparity in 3D space.
Do I need to rectify the image before calculating disparity?
The following are the steps that I have done so far for disparity map computation(I have tried with rectification and without rectification but both are returning all zeroes disparity matrix).
For each pixel in the left image X,
Take the pixels in the same row in the right image.
Separate the row in right image to windows.
For each window,
Calculate the disparity for each pixel in that window with X
Select the pixel in the window which gives minimum SSD with X
Find the pixel with minimum disparity among all windows as the best match to X
Am I doing it correctly?
How can I visualise the 3D reconstruction of the disparity as scatter plot in matlab?
Rectification guarantees that matches are to be found in the same row (for horizontally separated cameras). If you have doubts about rectification of your images you can try to compare rows by drawing horizontal lines between horizontally separated images. If the lines hit the same features you are fine, see the picture below where images are NOT rectified. The fact that they are distorted means there was a lens distortion correction as well as attempted (but not actually performed correctly) rectification.
Now, let’s see what you meant by the same images. Did you mean the images of the same object that were taken from different viewpoints? Note that if the images are literally the same (the same viewpoints) the disparity will be zero as was noted in another answer. The definition of disparity (for horizontally separated cameras) is a value of shift (in the same row) between matching features. The disparity is related to depth (if optical axes of cameras are parallel) as disparity d=f*B/z, where z - depth, B - baseline or separation between cameras and f is a focal length. You can transform the formula above into disparity/B=f/z which basically says that disparity related to camera separation as focal length is related to distance. In other words, the ratios of horizontal and distance measures are equal.
If your images are taken with the cameras shifted horizontally the disparity (in a simple correlation algorithm) is typically calculated in 5-embedded loops:
loop over image1 y
loop over image1 x
loop over disparity d
loop over correlation window y
loop over correlation window x
Disparity, or D_best, gives you the best matching window between image1 and image2 across all possible values of d. Finally, scatterplots are for 3D point clouds while disparity can be rather visualized as a heat color map. If you need to visualize 3D reconstruction or simply saying a 3D point cloud calculate X, Y, Z as:
Z=fB/D, X=uZ/f, Y=v*Z/f, where u and v are related to column and row of wxh image as
u=col-w/2 and v=h/2-row, that is u, v form an image centered coordinate system.
If your two images are exactly the same, then the disparity would be 0 for every pixel. You either have to use two separate cameras to take the images, or take them with a single camera from two different locations. The best way to do 3D reconstruction is to use a calibrated stereo pair of cameras. Here is an example of how to do that using the Computer Vision System Toolbox for MATLAB.

Finding the length/area of the object using 2d web cam

I have to calculate the area, or length of the objects present in the frame.
As i use the 2d camera, the distance from the camera can't be found.
In this case, i am planning to draw a constant(X CM) line in the back ground where its length is known in CM/M.
Please find the attachment for a sample input image. (Yellow Line is a Constant line)
Consider that a person or an object stands in front of a wall, where the constant line is drawn.
Is there any way to calculate the distance of other objects with reference to the constant line?
First, it isn't a line. It is a parcel. A line is non-physical. The parcel of pixels has both area and length. The natural unit of measurement of images is pixels. Units of length are both non-physical and require assumptions.
Second, you can do a thresholded 2-d convolution. PIV-sleuth uses 2d convolution. It can allow some faster, more accurate measurement in images. Peak intensity will tell you something about the length or area. You can also use row-sum and column sum very quickly to get ideas of lengths. It helps if the images are aligned to the pixel-axes in your image. Use of affine transformations can help you test various rotations for suitability.

in matlab, find 3D neighbourhood

I have a volume (3D matrix) that has undergone a segmentation process. Most of the volume consist of NaNs (or zeros), except regions that have passed some criteria (see picture). I need to know how large each remaining segment is in number of voxels and how is their distribution on the 2D planes (xy, xz, yz). Is there anything in matlab that can help me do this in an efficient way rather than direct search? The volume can be rather large. For ex. in the attached picture there is one segment in yellowish/brownish colour of 7 voxels and extends more vertically than in xy.
Thanks in advance.
The most convenient solution is to use REGIONPROPS. In your example:
stats = regionprops(image, 'area', 'centroid')
For every feature, there is an entry in the structure stats with the area (i.e. # of voxels) and the centroid.
I think that what you are looking for is called bwlabeln. It allows you to find blobs in 3D space, just like bwlabel does in 2D. Afterwards, you can use regionprops to find out the properties of the data.
Taken directly from help:
bwlabeln Label connected components in binary image.
L = bwlabeln(BW) returns a label matrix, L, containing labels for the
connected components in BW. BW can have any dimension; L is the same
size as BW. The elements of L are integer values greater than or equal
to 0. The pixels labeled 0 are the background. The pixels labeled 1
make up one object, the pixels labeled 2 make up a second object, and
so on. The default connectivity is 8 for two dimensions, 26 for three
dimensions, and CONNDEF(NDIMS(BW),'maximal') for higher dimensions.

Finding number of quantizing layers in MATLAB

I'm working on image processing, and I have an image that has been DCT'd and quantized for 8 x 8 blocks of the 512 x 512 matrix, now I have to find how many quantizing levels that the image has. Do I need to take the top left pixel and place it in to an array and then place this on a graph calling hist?
length(unique(x(:))), where x is your image array. This is appropriate for grayscale images.