how to reduce the running time of the code?
Show older comments
Hello, The following code takes around 25 minutes to run...it is based on image processing...i need to reduce the computation time of this code...this includes only the encryption and i still need to perform the decryption,....
clc
clear all
close all
A=imread('C:\Desktop\lena.png');
disp(A);
imshow(A);
for i=1:1:256
for j=1:1:256
B{i,j,1} = dec2bin(A(i,j),8); %%conversion of pixel values to 8 bit binary values from original image
end
end
disp(B);
M=randint(256,256,[0,256]); %%key image generation
disp(M);
for k=1:1:256
for l=1:1:256
N{k,l,1} = dec2bin(M(k,l),8);
end
end
disp(N);
figure,imshow(uint8(M));
%%DNA maping of binary values of original image
codebook1 = containers.Map({'00','11','10','01'},{'G','C','T','A'});
outputCell = cellfun(@(x) values(codebook1, {x(1:2),x(3:4),x(5:6),x(7:8)}),B, 'uni', 0);
C = cellfun(@cell2mat, outputCell, 'uni', 0);
disp(C);
ranopCell = cellfun(@(x) values(codebook1, {x(1:2),x(3:4),x(5:6),x(7:8)}),N, 'uni', 0);
O = cellfun(@cell2mat, ranopCell, 'uni', 0);
disp(O);
fun = @(t,v) chen1(t,v,a,b,c,d,k);
[t, v] = ode45(fun, [0 1.54], v0);
x = v(:,1);
x(257)=[];
y = v(:,2);
y(257)=[];
disp(x);
disp(y);
figure,plot(x,y);
%%sorting
[lx,fx]=sort(x);
[ly,fy]=sort(y);
S=fx;
T=(fy)';
%%matrix generated for scrambling
[Tgrid, Sgrid] = meshgrid( T, S );
Z = arrayfun( @(S,T) [S T], Sgrid, Tgrid, 'UniformOutput', false );
%%scrambled matrix
D=cellfun(@(x) C{x(1),x(2)},Z,'un',0);
disp(D);
P=cellfun(@(x) O{x(1),x(2)},Z,'un',0);
disp(P);
%%XOR operation
ind = reshape(1:65536, 256, 256);
E = arrayfun(@(x) letterXOR(D{x},P{x}), ind, 'uni', 0);
%%decoding using rule 4
codebook2 = containers.Map({'C','G','T','A'},{'00','11','10','01'}); %// Lookup-map values to key
outputCell1 = cellfun(@(x) values(codebook2, {x(1),x(2),x(3),x(4)}),E, 'uni', 0);
F = cellfun(@cell2mat, outputCell1, 'uni', 0);
disp(F);
G=cellfun(@bin2dec,F);
disp(G)
figure,imshow(uint8(G));
thanks in advance..
Accepted Answer
More Answers (2)
Guillaume
on 3 Sep 2014
1 vote
The method you're using to convert your integer matrices to DNA sequences is very inefficient (2 x for loops, wrong base, map lookups). I gave you a while back an extremely efficient method that does not involve any loop. See my answer to your previous question convert binary to charaacter. I doubt you could find a more efficient way of performing that conversion.
Similarly, I gave you an extremely efficient way to perform the xor operation in your other question how to perform bitwise XOR operation and scramble two matrices
As I've mentioned before, converting to binary is the wrong thing to do and unnecessarily complicate your code. You're actually operating in base 4, where G=0, C=1, T=2, A=3. If you use base 4, you're then using single digits, no more x(3:4).
Conclusion:
- precompute all the conversions,
- use base 4,
- use the profiler to see where the bottlenecks are.
Supreeth Murugesh
on 29 Aug 2017
0 votes
Which is the algorithm used in the above code ?
Categories
Find more on Loops and Conditional Statements 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!