How to convert pseudo code into MAT LAB ?
Mostrar comentarios más antiguos
dear all,
i have this pseudo code and i need to convert it into MATLAB please help me
/* inputs and variables / image cov_img, output_cov_img; / input and output images / bitstring secret_msg_bit; int embedding_bit_no; / will be input by user / int total_counter=1; / holds number of checked colors / int qualified_counter=1; / holds number of qualified colors / int secret_msg_bit_len= length(secret_msg_bit); input embedding_bit_no; input cov_img; qualified_counter_limit =ceiling(secret_msg_bit_len/embedding_bit_no); int threshold; output_cov_img= cov_img; input secret_msg_bit; bitstring cropped_secret_msg; int original_color; / holds the original value of the color / bitstring new_color; / holds the new value of the color after embedment / int height=height(cov_img); int width=width(cov_img); int total_color = height×width×3; int color_counter=1; int height_counter=1; / provides the height of the pixel to be checked / int width_counter=1; / provides the width of the pixel to be checked / intarray color_array[total_color]; / to hold all colors of the pixels in 1D array / int case_one; int case_zero; / start of the code / { / putting all colors of the cover image into a 1D array / copy the bytes of the cov_img into 1D array called color_array; sort color_array in descending manner; threshold is the qualified_counter_limit-th value of color_array; if qualified_counter_limit-th value of color_array does not exist then { Output “optimal threshold does not exist”; Exit; } while (qualified_counter <= qualified_counter_limit) / ensures embedment of whole the message / { if (most significant bits value(color_array[total_counter]) >= threshold) / ensures the color to be qualified / { original_color = color_array[total_counter]; / to be used in adaption / cropped_secret_msg = get next embedding_bit_no bits from secret_msg_bit[ (qualified_counter - 1)×embedding bit_no]; / to be replaced to lsb of the color / } new_color=Replace least significant bit(s)(color_array[total_count]) with cropped_secret_msg; qualified_counter = qualified_counter + 1; / counter increment / / matching (adaption) / case_one = decimal value of new_color by changing the matching bit to 1; case_zero = decimal value of new_color by changing the matching bit to 0; if original_color – case_one > original_color – case_zero then matching bit of new_color=0; else matching bit of new_color=1; replace corresponding color of output_cov_img with new_color; } total_counter= total_counter + 1; Show output_cov_img; } / End of the code */
Respuestas (3)
Image Analyst
el 28 de Sept. de 2013
2 votos
4 comentarios
sarah
el 28 de Sept. de 2013
Image Analyst
el 28 de Sept. de 2013
You need to take some of the tutorials, read the getting started section in the help, and then just start attacking it. Try running the program and fix the line where it throws an exception. Keep going until all the errors are gone.
Image Analyst
el 29 de Sept. de 2013
Here, I've done the majority of it for you. Please do the rest.
% inputs and variables
total_counter=1; % holds number of checked colors
qualified_counter=1; % holds number of qualified colors
secret_msg_bit_len= length(secret_msg_bit);
input embedding_bit_no;
input cov_img;
qualified_counter_limit =ceil(secret_msg_bit_len/embedding_bit_no);
output_cov_img= cov_img;
input secret_msg_bit;
bitstring cropped_secret_msg;
height=height(cov_img);
width=width(cov_img);
total_color = height * width * 3;
color_counter=1;
height_counter=1; % provides the height of the pixel to be checked
width_counter=1; % provides the width of the pixel to be checked
color_array[total_color]; % to hold all colors of the pixels in 1D array
case_one;
case_zero;
% putting all colors of the cover image into a 1D array
% copy the bytes of the cov_img into 1D array called color_array;
color_array = cov_img(:);
sortedColors = sort(color_array, 'ascend');
threshold is the qualified_counter_limit-th value of color_array;
if qualified_counter_limit-th value of color_array does not exist then
fprintf('optimal threshold does not exist\n');
return;
end
while (qualified_counter <= qualified_counter_limit)
% ensures embedment of whole the message
if (most significant bits value(color_array[total_counter]) >= threshold)
% ensures the color to be qualified
original_color = color_array[total_counter]; %to be used in adaption
cropped_secret_msg = get next embedding_bit_no bits from secret_msg_bit[
(qualified_counter - 1)×embedding bit_no]; % to be replaced to lsb of the color
end
new_color=Replace least significant bit(s)(color_array[total_count]) with cropped_secret_msg;
qualified_counter = qualified_counter + 1; % counter increment
% matching (adaption)
case_one = decimal value of new_color by changing the matching bit to 1;
case_zero = decimal value of new_color by changing the matching bit to 0;
if abs(original_color – case_one) > abs(original_color – case_zero)
matching_bit_of new_color=0;
else
matching_bit_of_new_color=1;
replace corresponding color of output_cov_img with new_color;
end
total_counter= total_counter + 1;
imshow(output_cov_img, []);
end
Jan
el 28 de Sept. de 2013
0 votos
Dear Sarah,
What kind of help do you expect? Should we shortly give a 20 hours crash course in Matlab? You are right, there is a lot to do before you can use Matlab efficiently. But there is no short cut, no magic secret knowledge which allows to speak Matlab fluently after reading one or two answers in this thread.
8 comentarios
sarah
el 28 de Sept. de 2013
Image Analyst
el 28 de Sept. de 2013
First you said convert it to MATLAB, now you're saying convert it to C++. Either way, you can either hire a consultant to do it for you, or do it yourself. It could be many hours of work to translate it, test it, document it, explain it to you, and turn it over to you. That's just too much time to expect anyone to devote to you for free.
Jan
el 28 de Sept. de 2013
@sarah: If you need this code for your graduate project, letting others do your work looks like cheating. It is the idea of a graduate project that the students learn how to manage the available time. If you really find somebody else for writing this, do not forget to mention this explicitly in the submission.
If you want to encourage somebody to help you, start with formatting the code such that it is readable. Without a formatting and without showing any own effort, the readers have the impression, that you are not really interested in your own problem.
sarah
el 29 de Sept. de 2013
sarah
el 29 de Sept. de 2013
Image Analyst
el 29 de Sept. de 2013
No I don't, or at least I'm not 100% sure. In your original post you said convert the pseudocode into MATLAB but in your first comment to Jan you said you were trying to convert it into C. I'm not sure what your desired end point is. Actually you can do both. First go into MATLAB, then use one of the toolboxes (Coder I think?) to translate from MATLAB into C. So you'll have both.
A strategy I might suggest. Firs get rid of oepning braces {. Then replace closing braces with "end". Then get rid of / and convert / into % symbols for comments. Replace "Show output_cov_img;" with "imshow(output_cov_img,[]);" Use ~exist() for "does not exist". Etc.
Then try to run it. Whenever it stops, fix that problem. Keep going until all the problems are fixed.
Marc
el 29 de Sept. de 2013
Maybe you should stick around for another semester or two and learn. It will only make you more valuable to your future employer.
Just a recommendation, in the future you should state your question and problem more clearly. Maybe even try and show the desired workflow you are attempting to describe. Especially if your not going to take a stab at the problem yourself.
Good luck
@sarah: If no one offered help, after you asked for it, you should think twice. You can see thousands of useful answers here. Why do the people hesitate to solve your problem?
Or from my point of view: You do not invest the time to format your code properly. Then I get the impression, that the problem is not really important for yourself. This does not encourage me to invest time also.
Edrin Kibalama
el 6 de Mzo. de 2020
0 votos
hello guyz can some one help please implement this pseudocode in matlab cause am really stuck.

Categorías
Más información sobre App Building en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!