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!