problem with typecast command
29 次查看(过去 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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!