vector optimization

3 次查看(过去 30 天)
Prajakta Shende
Prajakta Shende 2012-2-15
编辑: dpb 2013-10-19
i have written this code and i wish to use vectorization to the inner if loop. because the program takes a long long time to execute even for a 128x128 image. can someone please provide me with the vector optimization logic for the following code?
for i=1:row
for j=i+1:row
if C(i,g)==C(j,g)
P2(C(i,g+1):C(i,g+1)+in-1, C(i,g+2):C(i,g+2)+in-1)=0;
P2(C(j,g+1):C(j,g+1)+in-1, C(j,g+2):C(j,g+2)+in-1)=0;
end
end
end
  2 个评论
Andrei Bobrov
Andrei Bobrov 2012-2-15
What is it: 'C','P2','g','in'?
Prajakta Shende
Prajakta Shende 2012-2-22
C= is my overlapping block division array output. where one roq of C contains: all elements in one block and the starting row col positions of that block
in= blocksize
g= in*in. blocksize*blozksize. i have to access only till g. because i only have to compare the elements. i do not have to compare there positions as well.
P2= after matching C wid P2 all those positions where the regions are matching. ie. forgery is thr.. it will make it zero.
so P2 currently has forged image data. but after the above written loop exec it will contain. image data with forged part as black viz,. zero.
thanku! :)

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2012-2-15
Not a vectorization, but at least no repeated calculations in the inner loop:
for i=1:row
C_ig = C(i, g);
a = false;
for j=i+1:row
if C_ig == C(j,g)
a = true;
P2(C(j,g+1):C(j,g+1)+in-1, C(j,g+2):C(j,g+2)+in-1) = 0;
end
end
if a
P2(C(i,g+1):C(i,g+1)+in-1, C(i,g+2):C(i,g+2)+in-1) = 0;
end
end
  1 个评论
Prajakta Shende
Prajakta Shende 2012-2-22
this blackens the entire image..
basically what im doing is..
im dividing the image into overlapping blocks and storing it to array 'c'. now i add the starting block positions of the overlapping division to the array 'c' by concatenating the two and form C.
i access only till g because g= blocksize*blocksize. that is total no of elemnts in a block which will be in a particular row of C
and fow all those positions where the region is forged that is C=forged image block division array is matched with P2 currently holding forged image data. so, everyplace where P2=C it makes it equal to zero.
im attaching my code that i have written so far..
by ur this logic the execution was really really fast =)) but then i cudnt convert it to my code logic. it would be superb if u could help...
thanku :)
CODE:
tic;
clc;
clear all;
close all;
tic
p=imread('D:\image forgery\db\3.jpg');
P=rgb2gray(p);
P=imresize(P, [8 8]);
% P=[1,2,3,4;5,6,7,8;9,10,11,12;13,14,15,16];
P1=P;
% P1(30:46,30:46)=P(8:24,8:24);
P1(4:8,4:8)=P( 3:7,3:7);
imwrite(P1, 'D:\image forgery\P1.jpg');
imshow(P1);
in=input('Enter block size');
disp('Beginning block division using im2col');
c=im2col(P1,[in in],'sliding');
c=c';
[m,n]=size(P1);
y=0;
for i=1:m-in+1
for j=1:n-in+1
y=y+1;
pos(2,y)=i;
pos(1,y)=j;
end
end
pos=pos';
C=cat(2,c,pos);
g=(in*in);
P2=P1;
disp('Block division complete')
[row col]=size(C);
for i=1:row
for j=i+1:row
if C(i,g)==C(j,g)
P2(C(i,g+1):C(i,(g+1))+in-1,C(i,g+2):C(i,(g+2))+in-1)=0;
P2(C(j,g+1):C(j,(g+1))+in-1,C(j,g+2):C(j,(g+2))+in-1)=0;
end
end
end
imwrite(P2, 'D:\image forgery\P2.jpg');
% imshow(P2);
toc;

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by