How to normalize array into a Mat frame line

Hi everyone, first time here.

I have a camera from which I get “intensity” raw data, this comes at 25hz. This is a callback from the camera sdk that returns an array[]. The size of the array is 640 and the resolution is 10bit. Data is grayscale, meaning 1023 = white, 0 = black.
I have a mat of an arbitrary row size and 640 columns that I push back a row to every time I get a new frame line. I loose the top (row(0)) in this process which is ok, otherwise I’d have an ever-growing image. This is how I accomplish that:

mat1.rowRange(1, mat1.rows).copyTo(mat1);

My question is, what is the best way to normalize the 10 bit frame line from the C style array (ushort) to a 8 or 16 bit Mat?

is this a line scan camera or flatbed scanner? you said 25 Hz but you also said single rows. I’m also puzzled by its low resolution and low line rate.

first part: “rolling”

I’d treat it like a ring buffer. write to successive rows of a 2d “buffer” array, then assemble a “true” view from the two sections (next line to bottom, top to current line). if you don’t always need the true view, this allows you to save the copying effort sometimes.

second part: “normalizing”… depends on what you have there! could you show some sample data?

Hey thanks for the replay!
Data is an unsigned short array where the max value is 10 bit and length is 640 (the width of the laser array).
This “frame line” s come at 25hz like I said above and I can buffer some of the lines and then build the image to save on copy but unlike a flatbed there is no limit on how many lines come so it has to be a rolling Mat so I can do something like real-time line detection.

On the normalizing part since data is 10 bit, not sure if it’s better to get each line and >> 2 to do an CV_8CU1.

ah. you could use floating point and normalize to 0.01.0. it entirely depends on what you’re gonna do with the information. chopping the lower two bits off would be reasonable if they’re noisy or not relevant to the actual range of values you’re dealing with. or keep it all and keep the CV_16U type.