Перейти к содержимому

Arithmetic Coding in Digital Image Processing with example&its Implementation in MATLAB||Compression

Study with Dr. Dafda

0:00 / 0:00

Arithmetic Coding in Digital Image Processing with example&its Implementation in MATLAB||Compression

9 483 просмотра · 4 года назад
Study with Dr. Dafda
3,58 тыс. подписчиков
9 483 просмотра · 4 года назад
Video lecture series on Digital Image Processing, Lecture: 40, Arithmetic coding in Digital Image Processing with example and its Implementation in MATLAB Link to download ppts/lecture notes: https://drive.google.com/drive/folder... #DIP #DIPwithMATLAB #DigitalImageProcessingUsingMATLAB #DigitalImageProcessing #StudywithDrDafda MATLAB codes... % % %Program for Arithmetic close all; clear all; clc; str = 'dafda'; fprintf('The entered string is : %s\n', str); len = length(str); fprintf('The length of the string is : %d\n', len); % % % get unique characters from the string u = unique(str) % disp('the unique symbols/characters are'); % disp(u); fprintf('The unique characters are : %s\n', u); len_unique = length(u); fprintf('The length of unique character string is : %d\n', len_unique); % % % General lookup table % % % get zeros of length of unique characters z = zeros(1, len_unique); p = zeros(1, len_unique); for i = 1 : len_unique % % % in 'z' variable we find the occurrence of each characters from 'str' z(i) = length(findstr(str, u(i))); % % % in 'p' variable we will get probability of those occurrences p(i) = z(i) / len; end display(z); display(p); % % % in 'cpr' variable we will get the cumulative cpr = cumsum(p); % % % in 'newcpr' 'cpr' from '0' till last value of 'p' newcpr = [0 cpr]; display(cpr); display(newcpr); % % % make table upto size of 'len_unique' for i = 1 : len_unique % % % in first column we are placing 'newcpr' values table(i, 1) = newcpr(i); % % % in second column we are placing 'cpr' values table(i, 2) = cpr(i); end % % % Displaying the lookup table display('The lookup table is : ') display(table); % % % Encoder Table LL = 0; HL = 1; for i = 1 : len for j = 1 : len_unique % % % if the value from 'str' matches with 'u' then if str(i) == u(j); pos = j; j = j + 1; % % % displaying position of symbol in unique string display(pos); % % % getting the tag value of the matched character diff_range = HL - LL HL = LL + (diff_range .* table(pos, 2)) LL = LL + (diff_range .* table(pos, 1)) i = i + 1; break end end end % % % displaying tag value tag = LL; display(tag); %%% DECODING %%% str = ''; % str = []; for i = 1 : len for j = 1 : len_unique % % % If tag value falls between a certain range in lookup table then if tag (greater than or)= table(j, 1) && tag (less than) table(j, 2) pos = j; tag = (tag - table(pos, 1)) / p(j); % % % Getting the matched tag value character decoded_str = u(pos); % % % String concatenating 'decoded_str' into 'str' str = horzcat(str, decoded_str); break end end end % str=horzcat(str); % Displaying final decoded string disp('The decoded string is : '); display(str) % % %Program for Arithmetic encoding and decoding of an image close all; clear all; clc; I = imread('Cameraman.tif'); I = imresize(I, [3 NaN]); disp('the pixel values are:'); disp(I); subplot(1,2,1); imshow(uint8(I)); title('Original image'); str=reshape(I.',1,[] ); % Convert Image from 2D to 1D len = length(str); fprintf('The length of the string is : %d\n', len); u = unique(str) disp('the unique symbols/characters are'); disp(u); % fprintf('The unique characters are : %s\n', u); % length of the unique characters string len_unique = length(u); fprintf('The length of unique character string is : %d\n', len_unique); z = zeros(1, len_unique); p = zeros(1, len_unique); for i = 1 : len_unique z(i) = length(findstr(str, u(i))); p(i) = z(i) / len; end display(z); display(p); cpr = cumsum(p); newcpr = [0 cpr]; display(cpr); display(newcpr); % % % make table till 'len_unique' size for i = 1 : len_unique % % % in first column we are then placing 'newcpr' values table(i, 1) = newcpr(i); % % % in second column we are placing 'cpr' values table(i, 2) = cpr(i); end % % % Displaying the lookup table display('The lookup table is : ') display(table); % % % Encoder Table LL = 0; UL = 1; for i = 1 : len for j = 1 : len_unique % % % if the value from 'str' matches with 'u' then if str(i) == u(j); pos = j; j = j + 1; % % % displaying position of symbol in unique string display(pos); % % % getting the tag value of the matched character diff_range = UL - LL; UL = LL + (diff_range .* table(pos, 2)); LL = LL + (diff_range .* table(pos, 1)); i = i + 1; break end end end % % % displaying tag value tag = LL; display(tag); %%% DECODING %%% %str = ''; str = []; for i = 1 : len for j = 1 : len_unique % % % If tag value falls between a certain range in lookup table then if tag (greater than or)= table(j, 1) && tag (less than) table(j, 2) pos = j; tag = (tag - table(pos, 1)) / p(j); % % % Getting the matched tag value character decoded_str = u(pos); % % % Image pixel values concatenating 'decoded_str' into 'str' str = horzcat(str, decoded_str); break end end end % str=horzcat(str); % % % Displaying final decoded image pixel values display(str) DD=uint8(str); Restore=reshape(DD,3,3); subplot(1,2,2); imshow(Restore.'); title('Decoded Image');