フィルターのクリア

Is there a way to make my picture RGB again? Trying to test hamming code

2 ビュー (過去 30 日間)
zakhar
zakhar 2024 年 1 月 24 日
コメント済み: zakhar 2024 年 1 月 24 日
I am doing assignment about hamming code and its ability to repaire itself. i've read that to encode picure it should be a BW picture but is there a way to restore colours after decoding? it would really benefit my project.
i will add the code and the picture as an archive. I have wrote coments to help you look at it.
The site didnt let upload archive as RAR so please rename it before openning
Best regards, sorry for bad english.
  2 件のコメント
DGM
DGM 2024 年 1 月 24 日
編集済み: DGM 2024 年 1 月 24 日
Binarizing an image discards a massive amount of information. It is not a reversible process.
I don't know what you read, but I suspect that when it said something along the lines of encoding "a binary image", they meant to encode the entire file as a bitstream, not to binarize an RGB numeric array by thresholding its luma.
Recommending a different approach would require a better description of the goals/requirements.
zakhar
zakhar 2024 年 1 月 24 日
Thank you. My task was to simply encode an image add some noise to it and decode it. The goal was to observe how Hamming code will restore corrupted image. It is my first time using MATLAB so i did not know how to do it properly

サインインしてコメントする。

採用された回答

DGM
DGM 2024 年 1 月 24 日
編集済み: DGM 2024 年 1 月 24 日
Well, here's one example. It might not be the most practical sort of thing, but it's probably fairly instructive. I imagine this is more of an educational task than a practical application, so let's not complicate the error observation by having the JPG encoding inside the loop.
% read image
img = imread('scale_1200.jpg');
% measure the picture
[rows, cols, channels] = size(img);
% get k & n for hamming (value in brackets may be changed)
[h,g,n,k] = hammgen(2);
% image to binary
% we're assuming img is always uint8
binary_img = dec2bin(img(:),8); % convert to 8-bit char representation of binary
binary_img = binary_img == '1'; % convert from char to logical
% change size to fit the "k"
% bear in mind that we're not checking
% that numel(img) is integer-divisible by k
binary_img = reshape(binary_img.', [], k);
% encode image using hamming
hamming_encoded_img = encode(binary_img, n, k, 'hamming/binary');
% add noise
noisy_hamming_encoded_img = imnoise(hamming_encoded_img, 'salt & pepper');
% decode the image
decoded_noisy_img = decode(noisy_hamming_encoded_img, n, k, 'hamming/binary');
% reshape to regain original size
decoded_noisy_img = reshape(decoded_noisy_img, 8, []).'; % convert back to a Mx8 logical array
decoded_noisy_img = char(decoded_noisy_img + '0'); % convert back to char representation of binary
decoded_noisy_img_norm = bin2dec(decoded_noisy_img); % convert back to numeric
decoded_noisy_img_norm = reshape(decoded_noisy_img_norm, rows, cols, channels); % reshape back to a MxNx3 RGB array
decoded_noisy_img_norm = uint8(decoded_noisy_img_norm); % cast back to original class
% show images
subplot(1,2,1), imshow(img), title('original image');
subplot(1,2,2), imshow(decoded_noisy_img_norm), title('decoded image with noise');
% show the error
figure
imshow(imfuse(img,decoded_noisy_img_norm,'diff'),'border','tight')
immse(img,decoded_noisy_img_norm)
ans = 40.6133
I don't know if that's helpful or not.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHamming についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by