Getting an error using writebmp (line 14) Expected X to be one of these types: logical, uint8, single, double
3 次查看(过去 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 个评论
Walter Roberson
2024-5-12
Unrecognized function or variable 'LT2'.
Error in ExampleExt2 (line 38)
tn_one_block=uint32(LT2(uint32(one_block)));
回答(2 个)
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:
0 个评论
Image Analyst
2024-5-12
Try
bin = mat2gray(single(bin)); % Convert from uint32 to something imwrite likes.
imwrite(bin, 'Recovered.png');
1 个评论
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!