Extract RGB value to decode
显示 更早的评论

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
回答(1 个)
Walter Roberson
2019-4-5
0 个投票
rgb2ind passing in a colormap of your four colors to get color indices.
9 个评论
NITIN TIWARI
2019-4-5
Walter Roberson
2019-4-5
[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
2019-4-6
Walter Roberson
2019-4-6
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
2019-4-7
Walter Roberson
2019-4-7
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
2019-4-7
Walter Roberson
2019-4-7
bwareafilt(mask0, SomeParameterGoesHere) %get rid of small accidental matches
NITIN TIWARI
2019-4-9
编辑:NITIN TIWARI
2019-4-9
类别
在 帮助中心 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!