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)');
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Import, Export, and Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!