I'm trying to create a 2D Colour Barcode. Different columns of the matrix will have different colours. I'm unable to get the desired output. Please help me solving it. The colour of the last letter overlaps with the first column. The matrix is a 1024×1024 matrix.
a=(get(handles.inp,'string')); b=numel(a); %string length
c=1024/b; %dividing barcode into equal no. of columns (letters)
redChannel = zeros(1024, 1024, 'uint8');greenChannel = zeros(1024, 1024, 'uint8');blueChannel = zeros(1024, 1024, 'uint8');for i=1:b j=1:c:1024; if(a(i)=='A')redChannel(1:1024,j:j+c)=255; %red colour for letter A
greenChannel(1:1024,j:j+c)=0;blueChannel(1:1024,j:j+c)=0;%j=j+c+1;
elseif(a(i)=='B')redChannel(1:1024,j:j+c)=0;greenChannel(1:1024,j:j+c)=255; %green colour for letter B
blueChannel(1:1024,j:j+c)=0;%j=j+c+1;elseif(a(i)=='C')redChannel(1:1024,j:j+c)=255; %yellow colour for letter C
greenChannel(1:1024,j:j+c)=255;blueChannel(1:1024,j:j+c)=0;%j=j+c+1;elseif(a(i)=='D')redChannel(1:1024,j:j+c)=0;greenChannel(1:1024,j:j+c)=0;blueChannel(1:1024,j:j+c)=255; %blue colour for letter D
%j=j+c+1;endendcoloredImage = cat(3, redChannel, greenChannel, blueChannel);imshow(coloredImage)
Best Answer