Here is what I have discovered:
Problem:
The avi file that im currently generating is 8bit so the range is cut in half providing less shades between black and white. The pixel resolution doesnt change but the 'resolution of the intensity is decreased making pixels that were once slightly different in the image now look identical.
Analysis:
You are using two main functions in your program:
"
getframe()" and "
addframe()", the later one is used to add a frame to your open AVI file.
However, the "
addframe()" function adds frame to your AVI file with 8-bit precision, even if you open a .png file of 16-bit precision.
Here is an extract from "
addframe()" help [
#-Link-Snipped-#]:
aviobj = addframe(aviobj, frame)...frame can be either an indexed image (m-by-n) or a truecolor image (m-by-n-by-3) of double or uint8 precision.
Now, initially I too was confused with uint8/uint16/double, until I realized
you must use "double" instead of "uint16".
Here are some useful definitions:
uint8: Is 8 bit, or one Byte. 0 to 255 (0 black, 255 white).
uint16: Is 16 bits or 2 Bytes. 0 to 65535 or -32766 to 32766 something, not sure here.
Single: (src. wiki) Single precision is a computer numbering format that occupies one storage location in computer memory at a given address. A
single-precision number, sometimes simply a
single, may be defined to be an integer, fixed point, or floating point.
Double: (src. wiki) Double precision is a computer numbering format that occupies two adjacent storage locations in computer memory. A
double precision number, sometimes simply called a
double, may be defined to be an integer, fixed point, or floating point.
The solution:
I came to know that there are two ways to designate gray scale images. uint8 and double. The difference; double is more precise since it uses "
fraction, or decimal point" to display white to black gradient (0 to 1) instead of the uint8 method of 0 to 255 levels. Plus, "double" uses 64-bit storage to represent the fraction, much more accurate than 32-bit storage of "single" precision.
So now you know, use
double instead of
uint16. Where do you apply that?
In the original post its stated that you are receiving your images from a video source. If it is a webcam I think the problem can be solved.:
start(vid); %vid is the video object
mov = avifile('MOVIE.avi','compression','None') %your movie file object, use whatever compression.
while(vid.FramesAcquired<=100) % Loop to capture rectangular area and video from source and store frames in MOVIE.avi. Stop after 100 frames.
imgrgb = getdata(vid,1,'double'); %!IMPORTANT! Get data from video source of "double" precision. Original image in Color(RGB).
I =.2989*imgrgb😀,:,1)+.5870*imgrgb😀,:,2)+.1140*imgrgb😀,:,3); % Convert to grayscale, *SEE NOTE AT END!!
% <your code here to draw the rectangle>
mov = addframe(mov,I_withRect);
end
%% Garbage clearance
stop(vid);
mov = close(mov);
* NOTE:
My algorithm is the same as "im2gray"[#-Link-Snipped-#] uses, The grayscale image will be of original "double" precision, which can be easily sent to "addframe()" function, as the help stated, it will accept "double" and "uint8"!
Let me tell you, I could not write an AVI file with any program on my PC, which must be because of some problem with compression and
not related to this.
Hope I was of help.