필터 지우기
필터 지우기

Received Image Output Error

조회 수: 1 (최근 30일)
James Manns
James Manns 2024년 4월 29일
댓글: James Manns 2024년 4월 29일
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에서 Convert Image Type에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by