I am trying to encode a grsy image using turbo product code but it's not working. The code I tried is below:
clc
clear
N = [127;255];
K = [120;239];
img = imread('pout.tif');
img = de2bi(img);
resized = imresize(img,[prod(K) 1]);
enc = tpcenc(resized,N,K);
enc = double(enc);
dec = tpcdec(enc,N,K);
op_img = reshape(dec,[],8);
op_img = op_img.';
op_img = reshape(2.^(0:7)*op_img,[],15);
op_img = imresize(op_img,[290 240]);
op_img = uint8(op_img);
figure();imshow(op_img)
Can you please guide me with this?

댓글 수: 6

You forgot to mention, what the problem is. Sharing this important detail is essential when you want to get your problem solved.
Are you sure you want to resize your image to a single column?
resized = imresize(img,[prod(K) 1]); % ?!?
Neeraj Chimwal
Neeraj Chimwal 2021년 5월 7일
I don't want to resize my image but tpc encoder asks for a column vector that's why I did it
Jan
Jan 2021년 5월 7일
Then reshape is what you need, not imresize.
Neeraj Chimwal
Neeraj Chimwal 2021년 5월 8일
I also thought about that but for tpc, the input must be a vector of size [prod(k) 1], and if I convert my image to binary and reshape it, the number of rows becomes different.
Now to get the desired number of rows i.e. prod(k), I'll have to first resize image in such a way that after reshaping, the number of rows becomes prod(k).
As a newbie, the only method I can guess is to make calculations before and after reshaping my binary image. And I don't feel I am correct here.
Jan
Jan 2021년 5월 8일
imresize(img) canges the contents of the pixels by an interpolation. As far as I understand you only want to change the shape keeping the values of the pixels, so use: resized = img(:), which is an abbreviation for reshape(img, numel(img), 1).
Neeraj Chimwal
Neeraj Chimwal 2021년 5월 8일
Yes I want to convert it to vector keeping the value BUT I also want the vector to be of size = [prod(k) 1] for tpc encoder.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2021년 5월 6일
편집: Walter Roberson 2021년 5월 6일

1 개 추천

img = de2bi(img);
That is something by 8, where the something is the number of elements in the original image.
resized = imresize(img,[prod(K) 1]);
image resizing happens in 2D, so you are collapsing all 8 bits per entry into a single bit, and interpolating to 28680 rows. Is it deliberate that you are doing something similar to thresholding down to one bit per entry when you imresize() the 8 bits down to one ??
op_img = reshape(dec,[],8);
... No, you got rid of the 8 bits per entry when you imresize()'d
Maybe you should be doing
resized = de2bi(reshape(imresize(img, K),[],1), 8)

댓글 수: 9

Neeraj Chimwal
Neeraj Chimwal 2021년 5월 7일
tpc requires a binary input and I want my image to convert back to gray at the end that why I used de2bi().
Also tpc encoder asks for a column vector as an input that why I used imresize(img,[prod(k) 1]).
and what you said about colapsing 8 bits to 1, that's what I am having problem with.
Walter Roberson
Walter Roberson 2021년 5월 7일
As Jan indicated, you should use reshape() not imresize()
Neeraj Chimwal
Neeraj Chimwal 2021년 5월 8일
I also thought about that but for tpc, the input must be a vector of size [prod(k) 1], and if I convert my image to binary and reshape it, the number of rows becomes different.
Now to get the desired number of rows i.e. prod(k), I'll have to first resize image in such a way that after reshaping, the number of rows becomes prod(k).
As a newbie, the only method I can guess is to make calculations before and after reshaping my binary image. And I don't feel I am correct here.
Walter Roberson
Walter Roberson 2021년 5월 8일
Well, what you should really be doing is breaking up the input signal into blocks of length K, and encoding each block and "send" the results concatenated together. Then on the "receiver", break up the received data, decode each part, and concatenate the results together.
Neeraj Chimwal
Neeraj Chimwal 2021년 5월 13일
How do I do that? I am assuming cropping will do the work?
img_K = buffer(img(:), K);
if you have the Communications Systems Toolbox
Neeraj Chimwal
Neeraj Chimwal 2021년 5월 14일
Sorry but I didn't understand it completely. using buffer() my image vector will be divided into k number of samples right?
If so how do I use this for encoding?
It converts the image to row vector and tpc needs column vector, So I reshaped it into column vector but again the old problem of size exists.
Here is the screen shot.
filename = 'cameraman.tif';
N = [127;255];
K = [120;239];
pK = prod(K);
img = imread(filename);
imshow(img)
title('original')
%part 1 -- encoding
binimg8 = de2bi(img, 8).';
binimgK = buffer(binimg8(:), pK);
for J = size(binimgK,2) : -1 : 1 %reverse order for efficiency
enc(:,J) = tpcenc(binimgK(:,J),N,K);
end
%part 2 -- decoding
enc = double(enc);
for J = size(enc,2) : -1 : 1 %reverse order for efficiency
dec(:,J) = tpcdec(enc(:,J),N,K);
end
decimg8 = reshape(dec,8,[]) .';
op_img_dec = decimg8 * 2.^(0:7).';
op_img_dec = op_img_dec(1:numel(img)); %get rid of padding
op_img = uint8(reshape(op_img_dec, size(img)));
figure();
imshow(op_img)
title('reconstructed')
Neeraj Chimwal
Neeraj Chimwal 2021년 5월 15일
편집: Neeraj Chimwal 2021년 5월 15일
You are just amazing brother.
Thanks a lot not for just this time but for helping me before too

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기

질문:

2021년 5월 6일

편집:

2021년 5월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by