problem with typecast command
조회 수: 23 (최근 30일)
이전 댓글 표시
I have a array of dimensions 199*8180 of uint 8 type. I am using typecast command to convert it into unit16 type but I am getting an error message. The message is
Error using typecast The first input argument must be a vector.
can someone please help me with this.
Regards, Jatin
댓글 수: 0
답변 (2개)
Image Analyst
2013년 5월 16일
Try cast() instead of typecast().
image16 = cast(image8, 'uint16');
or simply
image16 = uint16(image8);
Multiply image8 by 256 before casting if you want to brighten it.
댓글 수: 1
Shashank Prasanna
2013년 5월 16일
IA, cast simple changes the datatype represented in ML where as typecast changes the underlying representation without changing the data. This is useful say when a hardware returns uint16 through a serial connection (but the data is actually double), you would need to typecast it. cast function here would simply change class uint16 to class double keeping the same data. The ambiguity arises from the nomenclature.
Here is an excerpt from the documentation of typecast:
typecast is different from the MATLAB® cast function in that it does not alter the input data. typecast always returns the same number of bytes in the output Y as were in the input X.
Shashank Prasanna
2013년 5월 16일
typecast only takes scalars or vectors. If you have a matrix you can convert it into a vector from a matrix and then use typecast
>> datauint8 = data(:);
>> datauint16 = typecast(datauint8,'uint16');
>> datamat = reshape(datauint16,199,8180);
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!