UIImage gets distorted/wrong size in UIImageView - ios

I have two UIImageView with dimension 64 x 16 and two images (#2x):
image1 (128 x 32)
image2 (80 x 32).
I've placed image1 in imageview1 and image2 in imageview2.
When I run the app, imageview1 looks ok, but imageview2 looks distorted. How to deal with different image sizes? I want the UIImageView size to be fixed (64 x 32).
Any help would be really appreciated

image1 with dimension 128 x 32 and image2 with dimension 80 x 32
Your 2x image should have 160 x 64, not 128 x 32.
Edit:
If you have a 64x16 points of UIImageView, that results in 128 x 32 pixels on a 2x scale screen, if you have an image with 80 x 32 pixels, that will get disorted if you try to put it inside a 64x16 point (128x32 pixels) UIImageView

Related

Convert Centroid points generated at Image Size 640 * 640 (image size) to size 622*1186 (image size)

I want to convert point (i.e 622,622) coordinates to other dimensional coordinates (622*1186) Using OpenCV. i.e I currently plotted the data at Image Size 640 * 640.
Now I want to plot it at 622*1186 Image size. I want to know the formula so that I can convert them. I am working with OpenCV.
Ok, So I am answering my own Question!
The formula to convert the point (x, y) from the original size (width_original, height_original) to a new size (width_new, height_new) is:
x_new = x * width_new / width_original
y_new = y * height_new / height_original
So, in the above case:
x_new = 622 * 1186 / 640 = 622 * 1186 / 640 = 1176.25
y_new = 622 * 1186 / 640 = 622 * 1186 / 640 = 1176.25
So the new coordinates of the point would be (1176.25, 1176.25) in the 622 x 1186 image.

Camera Intrinsic Matrix for DJI Phantom 4

I am trying to estimate a gues for the intrinsic matrix, K, of a DJI Phantom 4 drone. I know that the form of this matrix is:
but i cant seem to get the units right. Looking up the specs at https://www.dji.com/phantom-4/info#specs I find that the focal length is 8.88 (dosnt say units...) and the image dimensions are 4000x3000. WHat would K look like with these?
*PS, I am scaling down the images so they are smaller. Will this effect the K matrix I should use for openCV?
The page the OP linked to lists a FOV of 94 degrees. With an image width of 4000 pixels this corresponds to a focal length of
f = (4000 / 2) pixels / tan(94 / 2 degrees) = 1865 pixels
Absent any other calibration data, one should therefore use an estimated camera matrix of the form:
K = [ [1865, 0 , 2000],
[0 , 1865, 1500],
[0 , 0 , 1 ] ]
OP, you may have confused the specs of the P4 and the P4Pro, which have different sensors and lenses. The P4Pro, not the P4, has a focal length of 8.8mm. The P4 has a focal length of 3.61mm.
If you are indeed using images from a P4, Francesco's answer is correct.
However, if you are actually using images from a P4Pro, you need to use these values:
f = (4864 / 2) pixels / tan(84 / 2 degrees) = 2701 pixels
K = [ [2701, 0 , 2432],
[0 , 2701, 1824],
[0 , 0 , 1 ] ]
For future reference for anyone that may find this answer, here are the relevant specs for the P4 and P4Pro sensors/lenses:
Phantom 4:
Sensor size: 1/2.3" (6.17mm x 4.55mm)
Focal length (actual): 3.61mm
Focal length (35mm equivalent): 20mm
FOV: 94°
Image size: 4000×3000 pixels
Video frame size
UHD: 4096×2160 pixels
4K: 3840×2160 pixels
2.7K: 2704×1520 pixels
FHD: 1920×1080 pixels
HD: 1280×720 pixels
Phantom 4 Pro:
Sensor size: 1" (12.8mm x 9.6mm)
Focal length (actual): 8.88mm
Focal length (35mm equivalent): 24mm
FOV: 84°
Image size
3:2 aspect ratio: 5472×3648 pixels
4:3 aspect ratio: 4864×3648 pixels
16:9 aspect ratio: 5472×3078 pixels
Video frame size
C4K: 4096×2160 pixels
4K: 3840×2160 pixels
2.7K: 2720×1530 pixels
FHD: 1920×1080 pixels
HD: 1280×720 pixels
I think it is much better to work from the focal length in mm
https://www.dxomark.com/Cameras/DJI/Phantom4-Pro---Specifications
For P4 Pro:
13.2 x 8.8 so pixel size is = 0.00241 or 2.41 um focal length is 8.8mm
so focal length in pixel = 8.8 / 0.00241 = 3684.6 pixels
Incidentally in the image metadata, there is a field:
CalibratedFocalLength 3666.666504 (use exiftool to find it) so I think K should be
K = [ [3666.6, 0 , 2432],
[0 , 3666.6, 1824],
[0 , 0 , 1 ] ]

How to divide an image according to its dimensions and get RGb color of each pixel

If 110 X 110 dimension, editor generates pixel by pixel (COL X ROW) rgb color code starting from 0 to 109.
Example :
px0=,,,,,,,,,,,,e6ebf8,c6d1ef,b6c3eb,9fb1e5,a0b2e5,a1b3e6,8ba1df,869fdf,87a0e0,88a0df,8ba0e0,8da2e2,8ea3e2,8fa3e2,92a7e6,93a8e6,93a8e4,97abe8,9baaeb,9baaeb,9caaeb,9caaeb,9dabec,9eabed,9eaded,9dafed,9ab0e9,9aafe5,9cb2e6,9dafe1,9eafde,9eaed9,a0add7,a3add8,a2b2dd,a2b2df,a3b3e1,a4b4e1,a6b6e4,a7b8e4,a8b9e5,a9bae6,aeb9e6,afbae7,afbae8,afbbec,afbdf0,abbaf0,abbaf1,a9baf1,abbdf1,a7b9eb,a2b4e6,99aade,92a4d7,8ea0d1,8898cc,8898cb,8a99cb,8d9bcd,919ecf,909dcf,8d9bcc,8b99ca,8896c7,8693c4,8591c2,8391c0,8795c4,8c99c9,909ecd,93a0d0,95a3d2,99a6d7,99a7d6,97a6d4,98a6d7,96a3d4,92a0d1,909dcc,a1aad2,9aa4cb,959ec7,acb3d0,bdc2d8,e2e4ed,,,,,,,,,,,,|px1=,,,,,,,,,dce2f4,abbae6,8298da,7b93d9,7d95db,7f97dd,8098de,829add,839bde,839bde,849ddd,859ede,87a0e0,8ba0e0,8a9fdf,8ea3e2,90a2e2,8da0dd,9aadea,99ace7,96a9e3,a5b3eb,a1aee6,9eace4,99a6de,a1afe7,a1aee6,a0aee6,9eade4,92a5da,8b9ccd,8698c5,8490bb,737da2,7880a2,8286a4,888ba7,8990ac,8d96b2,949db9,969fbb,9ba4c0,9da6c2,,,,,,,,,|px2=,,,,,,,
and so on until px109

Transforming Line Points According to resized UIImage

I have UIImage with size 7017x4962 and have line points A(532,1118) and B(4114,1118).I have reduced the UIImage size to 2339x1654.How can I transform the line points according to new UIImage size.
Multiply x and y proportionate to the new image width and height for each coordinate pair:
x * (2339.0f / 7017.0f)
y * (1654.0f / 4962.0f)
This will give you A(177, 372) and B(1371, 372).

Trying to save image with high resolution(200 ppi)

In ios, by default while saving the image. It will renders 72 ppi image. But i want 200 or more dpi image.Resolution should not be change.
For example if i have 1200x1200 dimension image, while saving image it is 72 ppi but i wanted it as 200 or more ppi with same 1200x1200 dimensions
Code:
CGSize finalCanvasSize = CGSizeMake(1200*1200);
UIGraphicsBeginImageContextWithOptions(finalCanvasSize, NO, 0.0);
[canvasImage drawInRect:CGRectMake(0,0,finalCanvasSize.width,finalCanvasSize.height)];
resizedCanvasImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Resources