How can I change phase image to gray code?

1 次查看(过去 30 天)
name = ['C:\Users\User\Desktop\trail.jpg'];
im = imread(name); im = im(:,:,2);
im= im2double(im);
imbin = imbinarize(im);
imbin = qammod(imbin,4,'gray'); %this part doesn't work
I tried to use function bin2gray, but it didn't work anymore. Any other alternatives failed me. My only option is doing it mannualy by if but I know this is reallby bad solutions for this problem. (30 000 000 iterations).
This is theoretical scheme how to do it. I have 6 images with fringes.
My error log
Error using qammod
Expected input number 1, X, to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64
Instead its type was logical.
Error in qammod>validateInput (line 262)
validateattributes(x, {'numeric'}, {'real','integer','>=',0,'<',M}, mfilename, 'X', 1);
Error in qammod (line 94)
validateInput(x, M, bitInput, outputDataType);
Error in zad2 (line 24)
imbin = qammod(imbin,4,'gray');

回答(2 个)

VINAYAK LUHA
VINAYAK LUHA 2023-8-31
编辑:Walter Roberson 2023-8-31
Hi Lukasz,
As per my understanding, the issue is due to type mismatch between the formal and actual parameters that the “qammod” function takes.
Use the “im2double” function to typecast the matrix “imbin” from logical to double type prior to calling the “qammod” function to resolve the type mismatch error.
Here’s the documentation of “im2double” for your reference.
I hope it helps!

Walter Roberson
Walter Roberson 2023-8-31
编辑:Walter Roberson 2023-8-31
name = 'trial1.jpg';
im = imread(name);
if ndims(im) > 2; im = im(:,:,2); end
im= im2double(im);
imbin = double(imbinarize(im));
imbin = qammod(imbin,4,'gray');
whos
Name Size Bytes Class Attributes ans 1x35 70 char cmdout 1x33 66 char im 1920x1080 16588800 double imbin 1920x1080 33177600 double complex name 1x10 20 char
imagesc(real(imbin)); title('real'); colorbar
imagesc(imag(imbin)); title('imag'); colorbar
That particular file is an example of a rare grayscale JPEG image, so you have to be careful how you read it.
Note that imbinarize() converts each location to either false (less that the threshold) or true (greater than the threshold), which is an alphabet of size 2. You are asking for qammod to process it as if it were an alphabet of size 4. That will work, but it is a bit inefficient.

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by