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

4 次查看(过去 30 天)
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 个评论
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 CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by