Extract RGB value to decode

27 views (last 30 days)
NITIN TIWARI
NITIN TIWARI on 5 Apr 2019
Edited: NITIN TIWARI on 9 Apr 2019
I'm trying to create a 2D Colour Barcode steganography which decodes a barcode into its corresponding text. On clicking the "Decode" button, the image must be decoded into its textual form.
I have given red, green, yellow and blue colours for letters A, B, C, D respectively. I want to decode this image by making use of RGB pixel values which will decide what's the letter.
The expected output for above image is ADBCD. Please help me!
[File_Name, Path_Name] = uigetfile('D:\'); %upload image by clicking on "Upload" button
axes(handles.graph)
imshow([Path_Name,File_Name]) %display image on axes in GUI window

Answers (1)

Walter Roberson
Walter Roberson on 5 Apr 2019
rgb2ind passing in a colormap of your four colors to get color indices.
  9 Comments
NITIN TIWARI
NITIN TIWARI on 9 Apr 2019
Edited: NITIN TIWARI on 9 Apr 2019
function decode_Callback(hObject, eventdata, handles)
global img %using the global variable 'img' from the "upload" function
index=1; %initialise index of 'text' variable to 1
for i=150:200:1024
red=img(500,i,1); %extract value of 'R' at (500,i)
green=img(500,i,2); %extract value of 'G' at (500,i)
blue=img(500,i,3); %extract value of 'B' at (500,i)
if(red==255&&green==0&&blue==0)
text(index)='A'; %store the letter 'A' in array 'text'
index=index+1; %increment the index for next colour
set(handles.out,'string',text);
elseif(red==0&&green==255&&blue==0)
text(index)='B'; %store the letter 'B' in array 'text'
index=index+1; %increment the index for next colour
set(handles.out,'string',text);
elseif(red==255&&green==255&&blue==0)
text(index)='C'; %store the letter 'C' in array 'text'
index=index+1; %increment the index for next colour
set(handles.out,'string',text);
elseif(red==0&&green==0&&blue==255)
text(index)='D'; %store the letter 'D' in array 'text'
index=index+1; %increment the index for next colour
set(handles.out,'string',text);
end
end
Hey Walter, this is what I tried doing for decoding the image into text. I'm getting output as expected. The only thing I'm lacking in my code is to give automatic spacing between the colours. In my code, I have chosen a spacing of 200 pixels. This works well only if there are 5 columns (colours). If the no. of columns increase, their width will decrease and if the no. of columns decrease, their width will increase. So, the idea of increasing the x-coordinate by 200 will not work everytime. This is the only thing that remains to be done. Would you please help me out?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by