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
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 CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by