Azzera filtri
Azzera filtri

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

4 visualizzazioni (ultimi 30 giorni)
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 Commenti
Walter Roberson
Walter Roberson il 12 Mag 2024
Unrecognized function or variable 'LT2'.
Error in ExampleExt2 (line 38)
Hardik Khatri
Hardik Khatri il 12 Mag 2024
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 👍🏻.

Accedi per commentare.

Risposte (2)

DGM il 12 Mag 2024
Modificato: DGM il 13 Mag 2024
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)
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 il 12 Mag 2024
bin = mat2gray(single(bin)); % Convert from uint32 to something imwrite likes.
imwrite(bin, 'Recovered.png');
  1 Commento
DGM il 13 Mag 2024
Modificato: DGM il 13 Mag 2024
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.

Accedi per commentare.


Scopri di più su Data Type Conversion in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by