Extract RGB value to decode
Show older comments

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
on 5 Apr 2019
0 votes
rgb2ind passing in a colormap of your four colors to get color indices.
9 Comments
NITIN TIWARI
on 5 Apr 2019
Walter Roberson
on 5 Apr 2019
[File_Name, Path_Name] = uigetfile('D:\');
fullname = fullfile(Path_Name, File_Name);
img = imread(fullname);
letters = {'A', 'B', 'C', 'D'};
cmap = [1 0 0; %red
0 1 0; %green
1 1 0; %yellow
0 0 1]; %blue
lettermap = rgb2ind(img, cmap);
letterimg = letters(lettermap);
NITIN TIWARI
on 6 Apr 2019
Walter Roberson
on 6 Apr 2019
You create read_image in the workspace of upload_Callback . It is a local variable, and so disappears as soon as upload_Callback returns. It is not available when you call decode_Callback .
http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
I do see one correction to my code:
letterimg = letters(lettermap + 1);
Note that letterimg will be an array with the same number of rows and columns and the original image. Deciding what part to extract from that is a different task. For example I made no effort at all to try to figure out how wide a bar "should" be in order to figure out whether it started ADB or instead starts AADDBB, and no attempt to remove the background area. The code I posted shows how to efficiently take pixels and turn them into numbers by color, and how to convert numbers to corresponding letters.
hints:
- you might want to expand cmap to include the background colors.
- bwareafilt
NITIN TIWARI
on 7 Apr 2019
Walter Roberson
on 7 Apr 2019
This sounds like an assignment. If I were to write the code for you, then you would not be doing the assignment yourself and so would not be able to hand in the code.
I will give a further hint:
mask0 = lettermap == 0; %true only where it was the first color
Now you can remove portions of the mask0 that are too small to be histogram bars, and you can analyze each remaining blob to figure out how wide it is, in order to decide how many letters in a row of that variety there were.
NITIN TIWARI
on 7 Apr 2019
Walter Roberson
on 7 Apr 2019
bwareafilt(mask0, SomeParameterGoesHere) %get rid of small accidental matches
NITIN TIWARI
on 9 Apr 2019
Edited: NITIN TIWARI
on 9 Apr 2019
Categories
Find more on Creating, Deleting, and Querying Graphics Objects 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!