Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear; clc; close all;
- tic
- %desired image size is 170x170
- image = imread('C:\Users\Joshua\Desktop\GIMP\Logos\cass.jpg');
- %colorMap = [.2 .2 .2; .8 .8 .8; .8 .2 .2; .2 .8 .2; .2 .2 .8; .8 .8 .2; .2 .8 .8; .8 .2 .8; .4 .4 .4; .6 .6 .6];
- %not really sure
- % colorMap = [0 0 0; 1 1 1; 1 0 0; 0 1 0; 0 0 1; 1 1 0; 0 1 1; 1 0 1;.25 .25 .25; .5 .5 .5; .75 .75 .75; 1 .5 0; .65 .15 .15];
- % colorStr = ['e';'w';'r';'g';'b';'y';'c';'p';'d';'m';'l';'o';'a'];
- %grayscale
- % colorMap = [0 0 0; 1 1 1; .25 .25 .25; .5 .5 .5; .75 .75 .75];
- % colorStr = ['e';'w';'d';'m';'l'];
- %color wheel
- colorMap = [0 0 0; 1 1 1; .25 .25 .25; .5 .5 .5; .75 .75 .75; 1 0 0; 0 1 0; 0 0 1; 1 .5 0; 1 1 0; 1 0 1];
- colorStr = ['e';'w';'d';'m';'l';'r';'g';'b';'o';'y';'p'];
- imageConv = rgb2ind(image, colorMap, 'dither');
- imageRGB = ind2rgb(imageConv, colorMap);
- [rows, columns] = size(imageConv);
- charCount = 1;
- lastChar = -1;
- charString = '';
- for row = 1:rows
- for col = 1:columns
- thisChar = imageConv(row, col);
- if col == 1
- charCount = 1;
- elseif thisChar == lastChar
- charCount = charCount + 1;
- elseif col~= 1
- charString = strcat(charString, sprintf('%s%i;', colorStr(lastChar+1), charCount));
- charCount = 1;
- end
- lastChar = thisChar;
- end
- charString = strcat(charString, sprintf('%s%i;n;', colorStr(lastChar+1), charCount));
- % charCount = 1;
- end
- figure
- hold on
- subplot(1,2,1)
- imagesc(image)
- subplot(1,2,2)
- imagesc(imageRGB)
- hold off
- toc
- fprintf('Encoded Length: %i\n', length(charString));
- disp(charString);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement