jjjkkkjjj / Matft

Numpy-like library in swift. (Multi-dimensional Array, ndarray, matrix and vector library)
BSD 3-Clause "New" or "Revised" License
134 stars 21 forks source link

Image processing #33

Open jjjkkkjjj opened 2 years ago

jjjkkkjjj commented 2 years ago

Create OpenCV Mat by https://stackoverflow.com/questions/39579398/opencv-how-to-create-mat-from-uint8-t-pointer

and pass it by “with” statements.

simple image processing function is vImage Module

FFFF means float types (8888 means UInt8)

https://developer.apple.com/documentation/accelerate/1515929-vimageconvolve_argbffff

jjjkkkjjj commented 2 years ago

https://docs.opencv.org/3.1.0/d3/d63/classcv_1_1Mat.html#a5fafc033e089143062fd31015b5d0f40

Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data. Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically deallocated, so you should take care of it.

jjjkkkjjj commented 2 years ago

https://github.com/jjjkkkjjj/Matft/blob/7bd5406b1286f7ac4d002be07cab847ba32349bd/Sources/Matft/library/vDSP.swift#L1415

bitspercomponent = 32 means float? If so, this is more efficient

According to core graphics supposed pixel formats, it only supports RGB with float format on iOS not Gray on iOS

ref: CGContext

jjjkkkjjj commented 2 years ago

I think CGContext documents implies passing data pointer will not be freed (= not copied )

data: A pointer to the destination in memory where the drawing is to be rendered. The size of this memory block should be at least (bytesPerRow*height) bytes. Pass NULL if you want this function to allocate memory for the bitmap. This frees you from managing your own memory, which reduces memory leak issues.

jjjkkkjjj commented 2 years ago

Ref: Float CGContext

https://stackoverflow.com/questions/55433107/how-to-normalize-pixel-values-of-an-uiimage-in-swift

jjjkkkjjj commented 2 years ago

The difference between Planar and interleaved image link Planar: Column contiguous Interleaved: Row contiguous

https://developer.apple.com/documentation/accelerate/optimizing_image-processing_performance