Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ann = my_nnmex(A, B)
- % function ann = my_nnmex(A, B,~, ~, ~, ~, ~, ~, ~, ~, ~,~,nnfield_prev)
- %function ann = nnmex(A, B, [algo='cpu'], [patch_w=7], [nn_iters=5], [rs_max=100000], [rs_min=1], [rs_ratio=0.5], [rs_iters=1.0], [cores=2], [bmask=NULL]...
- % [win_size=[INT_MAX INT_MAX]], [nnfield_prev=[]], [nnfield_prior=[]], [prior_winsize=[]], [knn=1], [scalerange=4])
- % (Pass [] to leave a parameter at its default).
- %ann = nnmex(res, img, algo, [], [], [], [], [], [], cores, [], [], ann);
- % ann size = B size
- % BEGIN DEBUGGING CODE
- % clear;
- % clc;
- % close all;
- % tic
- % image = imread('SimakovFarmer.png');
- % imageLab = rgb2lab(image); % Convert the source and target Images
- % imageLab = double(imageLab)/255;
- % targetHeight = 35;
- % res = imresize(imageLab,[targetHeight,NaN]);
- % stage1 = res;
- % H = 35;
- % % disp('Retargeting at the coarsest scale:')
- %
- % W = 30;
- % fprintf('\nH=%d, W=%d\n',H,W);
- % stage2 = imresize(stage1,[H,W]);
- % A = stage2; % small image
- % B = res; % large image
- % END DEBUGGING CODE
- sizeA = size(A);
- sizeB = size(B);
- w = 7;
- w1 = w-1;
- xALimit = sizeA(2) - w1;
- yALimit = sizeA(1) - w1;
- xBLimit = sizeB(2) - w1;
- yBLimit = sizeB(1) - w1;
- cost = zeros(yBLimit,xBLimit);
- ann = zeros(size(A));
- ann(:,:,3) = ones(sizeA(1),sizeA(2))*2147483647;
- % class(A)
- pause(0.01)
- % if (~ isa(A,'double'))
- % A = double(A)/255;
- % end
- % maxA = max(A(:))
- % maxB = max(B(:))
- % class(A)
- % class(B)
- A255 = A*255;
- B255 = B*255;
- % patchB_cache = cell(yALimit,xALimit);
- % for xB = 1:xBLimit
- % for yB = 1:yBLimit
- % patchB_cache{yB,xB}= B255(yB:yB+w1,xB:xB+w1);
- % end
- % end
- % patchB_cache(yALimit,xALimit) = struct('patch',zeros(w,w));
- % patchB_cache(1:yALimit,1:xALimit) = struct('patch',zeros(w,w));
- patchB.p=zeros(w,w);
- patchB_array = repmat(patchB,yBLimit,xBLimit);
- % patchB_cache(yALimit,xALimit)=struct();
- for xB = 1:xBLimit
- for yB = 1:yBLimit
- patchB_array(yB,xB).p = B255(yB:yB+w1,xB:xB+w1);
- end
- end
- % tic
- for xA = 1:xALimit
- % fprintf('xA=%d\n',xA)
- disp(xA)
- for yA = 1:yALimit
- patchA = A255(yA:yA+w1,xA:xA+w1); % small image
- for xB = 1:xBLimit
- for yB = 1:yBLimit
- % patchB = B255(yB:yB+w1,xB:xB+w1); % large image
- % costM = (patchB - patchA).^2;
- % patchB_array(yB,xB).p
- costM = (patchB_array(yB,xB).p - patchA).^2;
- cost(yB,xB) = sum(costM(:));
- end
- end
- [minVal,minLoc] = min(cost(:));
- [locY,locX]=ind2sub(size(cost),minLoc);
- ann(yA,xA,1)=locX - 1;
- ann(yA,xA,2)=locY - 1;
- ann(yA,xA,3)=minVal;
- % ann(yA,xA,3)=(locY-yA)^2 + (locX - xA)^2;
- % ann(yA,xA,3)= sum(costM(:))
- % d = (patchB - patchA)
- % ann(yA,xA,3)= d*d'
- end
- end
- % toc
- ann = int32(ann);
- % ann2 = nnmex(A, B, [], [], [], [], [], [], [], []);
- % whos ann
- % pause(0.01)
- % toc
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement