Getting an error using writebmp (line 14) Expected X to be one of these types: logical, uint8, single, double

3 ビュー (過去 30 日間)
Hardik Khatri
Hardik Khatri 2024 年 5 月 12 日
編集済み: DGM 2024 年 5 月 13 日
I am new to MATLAB and am getting the above error in my code. In my code, I read an altered (steganographic) image and extract a few bits from it. The embedding process went smoothly, but I am having some issues with the code's extraction.
  2 件のコメント
Walter Roberson
Walter Roberson 2024 年 5 月 12 日
Unrecognized function or variable 'LT2'.
Error in ExampleExt2 (line 38)
tn_one_block=uint32(LT2(uint32(one_block)));
Hardik Khatri
Hardik Khatri 2024 年 5 月 12 日
Thanks for helping for now it seems I have sorted out the issue. If I will face the error again, I will post here. Thanks for being actively helping everyone Walter 👍🏻.

サインインしてコメントする。

回答 (2 件)

DGM
DGM 2024 年 5 月 12 日
編集済み: DGM 2024 年 5 月 13 日
When I run it, it never actually gets that far without error.
Index exceeds the number of array elements (65528).
Error in ExampleExt2 (line 91)
pixelarray=pixelarray([1:msgW*msgH]);
So I don't know what the output actually looks like, but I'm going to take a guess based on the incomplete array that it assembled before it failed.
I'm guessing based on the distribution of values that it's actually uint8-scale data that's cast as uint32. If that's the case, then just cast it to the proper class for its scale using uint8().
% put the data in the proper class
bin = uint8(bin);
If instead the image is a properly-scaled uint32 image, then:

Image Analyst
Image Analyst 2024 年 5 月 12 日
Try
bin = mat2gray(single(bin)); % Convert from uint32 to something imwrite likes.
imwrite(bin, 'Recovered.png');
  1 件のコメント
DGM
DGM 2024 年 5 月 13 日
編集済み: DGM 2024 年 5 月 13 日
Why? The variable bin appears to be uint8-scale data cast as uint32. If that's indeed the case, just use uint8().
More generally, why is it always appropriate to blindly ruin contrast information with mat2gray() instead of figuring out what the scale should be?
Also, why explicitly cast a uint32 array as single before passing it to mat2gray()? The first thing mat2gray() does is cast its input as double, so this is an entirely unnecessary complication which can only cause damage to the data by momentarily reducing the precision of the data.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by