Received Image Output Error

1 次查看(过去 30 天)
Need help identifying why received image does not show. An error message does not show when I run the code.
clc;
clear all;
% Load the 'lenna' image
lenna = imread('lenna.png');
% Convert the image to grayscale
lenna_gray = rgb2gray(lenna);
% Convert pixel values to bits
lenna_bits = reshape(de2bi(lenna_gray), [], 1);
% Define Eb/No values for low and high SNR
Eb_No_low = 0;
Eb_No_high = 4;
% Calculate SNR values for low and high SNR
SNR_low = 10^(Eb_No_low/10);
SNR_high = 10^(Eb_No_high/10);
% Transmit and receive at low SNR
received_low = awgn(double(lenna_bits), SNR_low, 'measured');
% Demodulate received bits at low SNR
decoded_low = received_low < 0;
% Reshape decoded bits to original image size at low SNR
decoded_image_low = reshape(decoded_low, size(lenna_gray, 1), []);
% Plot original and received image at low SNR
figure;
subplot(1, 2, 1);
imshow(lenna_gray);
title('Original Image');
subplot(1, 2, 2);
imshow(decoded_image_low);
title('Received Image (0 dB SNR)');
% Define the parity matrix
parityMatrix = [1 1 0 1 0 0 0;
1 0 1 0 1 0 0;
0 1 1 0 0 1 0;
1 1 1 0 0 0 1];
% Concatenate the identity matrix and the transposed parity matrix to form the generator matrix
generatorMatrix = [eye(4), parityMatrix]; % Transpose parityMatrix to make its dimensions compatible
% Transmit and receive at high SNR
received_high = awgn(double(lenna_bits), SNR_high, 'measured');
% Demodulate received bits at high SNR
decoded_high = received_high < 0;
% Reshape decoded bits to original image size at high SNR
decoded_image_high = reshape(decoded_high, size(lenna_gray, 1), []);
% Plot original and received image at high SNR
figure;
subplot(1, 2, 1);
imshow(lenna_gray);
title('Original Image');
subplot(1, 2, 2);
imshow(decoded_image_high);
title('Received Image (4 dB SNR)');

采纳的回答

DGM
DGM 2024-4-29
编辑:DGM 2024-4-29
Again, look at the size of the arrays.
% Reshape decoded bits to original image size at low SNR
szin = size(lenna_gray,1:2);
decoded_image_low = reshape(decoded_low, prod(szin), []); % reshape into binary words
decoded_image_low = uint8(bi2de(decoded_image_low)); % convert to uint8 vector
decoded_image_low = reshape(decoded_image_low, szin); % devectorize
  1 个评论
James Manns
James Manns 2024-4-29
Would this be the same for the high SNR error?
% Reshape decoded bits to original image size at high SNR
szin = size(lenna_gray,1:2);
decoded_image_high = reshape(decoded_low, prod(szin), []); % reshape into binary words
decoded_image_high = uint8(bi2de(decoded_image_high)); % convert to uint8 vector
decoded_image_high = reshape(decoded_image_high, szin); % devectorize

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Import, Export, and Conversion 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by