problem with typecast command
19 ビュー (過去 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!