x-input(\'Enter valid Roman string\') R-roman2num (x); function R-roman if ischa
ID: 3836812 • Letter: X
Question
x-input('Enter valid Roman string') R-roman2num (x); function R-roman if ischar(x) x = (x) The above table represents a color decoding scheme for pixel data. The various color in column represented by color ID tags listed in column 1 (8-15). Write a MATLAB function with header function [ID, COLOR] = pixeldata(A) that will convert an array of pixel codes and corresponding color and IDs. Consider the following test case: A = 11000, 1111, 1100, 1001, 1001) represents the pixel codes for a small segment, your function should convert this information to: ID = 18, 15, 12, 9, 9] COLOR = Black White Red Blue Blue i. Develop a pseudo code to solve the above problem. ii. Write the appropriate MATLAB statements for each step. iii. Test you, solution by writing a MATWB function on your computer and submit a point copy/email attachment of your code.Explanation / Answer
Given below is pseudo code and MATLAB program for converting an array of pixel codes to corresponding IDs and colors. Comments are added in the program for mapping each step to MATLAB statements.
Pseudo Code:
function pixeldata(A)
Input: An array of pixel codes
Output: An array of corresponding pixel IDs and a string of corresponding colors
Step 1) Initialize color scheme array with ID and color for each available pixel code
Step 2) Initalize output variables
Step 3) Iterate through each pixel code in input array
Step 4) Iterate through each color scheme
Step 5) If pixel code in input array matches with code in color scheme array, then update corresponding ID and color in output variables
File: pixeldata.m
function [ID, COLOR] = pixeldata(A)
% This function converts an array of pixel codes and produces an output
% with corresponding IDs and colors.
% Initialize color scheme array with ID and color for each available pixel code
colorScheme(1) = struct('ID', 8, 'CODE', 1000, 'COLOR', 'Black');
colorScheme(2) = struct('ID', 9, 'CODE', 1001, 'COLOR', 'Blue');
colorScheme(3) = struct('ID', 10, 'CODE', 1010, 'COLOR', 'Green');
colorScheme(4) = struct('ID', 11, 'CODE', 1011, 'COLOR', 'Teal');
colorScheme(5) = struct('ID', 12, 'CODE', 1100, 'COLOR', 'Red');
colorScheme(6) = struct('ID', 13, 'CODE', 1101, 'COLOR', 'Magenta');
colorScheme(7) = struct('ID', 14, 'CODE', 1110, 'COLOR', 'Yellow');
colorScheme(8) = struct('ID', 15, 'CODE', 1111, 'COLOR', 'White');
% Initalize output variables
ID = [];
COLOR = '';
% Iterate through each pixel code in input array
for i = 1 : length(A)
code = A(i);
% Iterate through each color scheme
for j = 1 : length(colorScheme)
% Compare pixel code in input array against code in color scheme array
if (colorScheme(j).CODE == code)
% Found matching color scheme
ID = [ID colorScheme(j).ID];
COLOR = [COLOR ' ' colorScheme(j).COLOR];
break;
end
end
end
Execution Output:
> A=[1000, 1111, 1100, 1001, 1001]
A =
1000 1111 1100 1001 1001
> [ID, COLOR] = pixeldata(A)
ID =
8 15 12 9 9
COLOR = Black White Red Blue Blue
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.