Clear Filters
Clear Filters

Need help with Turbo product code

3 views (last 30 days)
Neeraj Chimwal
Neeraj Chimwal on 6 May 2021
Edited: Neeraj Chimwal on 15 May 2021
I am trying to encode a grsy image using turbo product code but it's not working. The code I tried is below:
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);
Can you please guide me with this?
Jan on 8 May 2021
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 on 8 May 2021
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.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 6 May 2021
Edited: Walter Roberson on 6 May 2021
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)
Walter Roberson
Walter Roberson on 14 May 2021
filename = 'cameraman.tif';
N = [127;255];
K = [120;239];
pK = prod(K);
img = imread(filename);
%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);
%part 2 -- decoding
enc = double(enc);
for J = size(enc,2) : -1 : 1 %reverse order for efficiency
dec(:,J) = tpcdec(enc(:,J),N,K);
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)));
Neeraj Chimwal
Neeraj Chimwal on 15 May 2021
Edited: Neeraj Chimwal on 15 May 2021
You are just amazing brother.
Thanks a lot not for just this time but for helping me before too

Sign in to comment.


Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!