网上matlab生成随机纹理的代码,不太会用,有没有大佬帮忙指导一下,万分感谢!

闫总的女粉丝 2021-03-20 05:27:04
%function Y = imagequilt(X, tilesize, n, overlap, err) %Performs the Efros/Freeman Image quilting algorithm on the input % %Inputs % X: The source image to be used in synthesis % tilesize: the dimensions of each square tile. Should divide size(X) evenly % n: The number of tiles to be placed in the output image, in each dimension % overlap: The amount of overlap to allow between pixels (def: 1/6 tilesize) % err: used when computing list of compatible tiles (def: 0.1) function Y = imagequilt(X, tilesize, n, overlap, err) X = double(X); if( length(size(X)) == 2 ) X = repmat(X, [1 1 3]); elseif( length(size(X)) ~= 3 ) error('Input image must be 2 or 3 dimensional'); end; simple = 1Z if( nargin < 5 ) err = 0.002; end; if( nargin < 4 ) overlap = round(tilesize / 6); end; % if( size(X,1) ~= size(X,2) ) % error('Must be square'); % end; if( overlap >= tilesize ) error('Overlap must be less than tilesize'); end; destsize = n * tilesize - (n-1) * overlap Y = zeros(destsize, destsize, 3); for i=1:n, for j=1:n, startI = (i-1)*tilesize - (i-1) * overlap + 1; startJ = (j-1)*tilesize - (j-1) * overlap + 1; endI = startI + tilesize -1 ; endJ = startJ + tilesize -1; %Determine the distances from each tile to the overlap region %This will eventually be replaced with convolutions distances = zeros( size(X,1)-tilesize, size(X,2)-tilesize ); % K = ones(tilesize, overlap); % y = Y(startI:endI,startJ:endJ,1:3); % for k=1:3, % % end; % M = zeros(tilesize, tilesize); % M(1:overlap,:) = 1; % M(:,1:overlap) = 1; % % y = Y(startI:endI,startJ:endJ,1:3); % a = (y(:,:,1) .* M) + (y(:,:,2) .* M) + (y(:,:,3) .* M); % a2 = sum(sum(sum(a.^2))); % % %a2 = sum(sum(sum(a.^2))); % % b2 = filter2(M, b.^2); % % ab = filter2(a, b); % % distances = sqrt(a2 + (2*ab + b2)); % distances = distances(1:size(X,1)-tilesize, 1:size(X,2)-tilesize); % b2 = filter2(X, zerosones(tilesize, tilesize) % % a2 = sum(sum(Y(startI:endI, startJ:startJ+overlap-1, 1:3).^2)) + ... % sum(sum(Y(startI:startI+overlap-1,startJ+overlap:endJ, 1:3).^2)); % b2 = sum(sum( % useconv = 1; if( useconv == 0 ) %Compute the distances from the template to target for all i,j for a = 1:size(distances,1) v1 = Y(startI:endI, startJ:endJ, 1:3); for b = 1:size(distances,2), v2 = X(a:a+tilesize-1,b:b+tilesize-1, 1:3); distances(a,b) = myssd( double((v1(:) > 0)) .* (v1(:) - v2(:)) ); %distances(a,b) = D; end; end; else %Compute the distances from the source to the left overlap region if( j > 1 ) distances = ssd( X, Y(startI:endI, startJ:startJ+overlap-1, 1:3) ); distances = distances(1:end, 1:end-tilesize+overlap); end; %Compute the distance from the source to top overlap region if( i > 1 ) Z = ssd( X, Y(startI:startI+overlap-1, startJ:endJ, 1:3) ); Z = Z(1:end-tilesize+overlap, 1:end); if( j > 1 ) distances = distances + Z; else distances = Z; end; end; %If both are greater, compute the distance of the overlap if( i > 1 && j > 1 ) Z = ssd( X, Y(startI:startI+overlap-1, startJ:startJ+overlap-1, 1:3) ); Z = Z(1:end-tilesize+overlap, 1:end-tilesize+overlap); distances = distances - Z; end; %distances = distances(1:end-tilesize, 1:end-tilesize); end; %Find the best candidates for the match best = min(distances(:)); candidates = find(distances(:) <= (1+err)*best); idx = candidates(ceil(rand(1)*length(candidates))); [sub(1), sub(2)] = ind2sub(size(distances), idx); fprintf( 'Picked tile (%d, %d) out of %d candidates. Best error=%.4f\n', sub(1), sub(2), length(candidates), best ); %If we do the simple quilting (no cut), just copy image if( simple ) Y(startI:endI, startJ:endJ, 1:3) = X(sub(1):sub(1)+tilesize-1, sub(2):sub(2)+tilesize-1, 1:3); else %Initialize the mask to all ones M = ones(tilesize, tilesize); %We have a left overlap if( j > 1 ) %Compute the SSD in the border region E = ( X(sub(1):sub(1)+tilesize-1, sub(2):sub(2)+overlap-1) - Y(startI:endI, startJ:startJ+overlap-1) ).^2; %Compute the mincut array C = mincut(E, 0); %Compute the mask and write to the destination M(1:end, 1:overlap) = double(C >= 0); %Y(startI:endI, startJ:endJ, :) = filtered_write(Y(startI:endI, startJ:endJ, :), ... % X(sub(1):sub(1)+tilesize-1, sub(2):sub(2)+tilesize-1, :), M); %Y(startI:endI, startJ:endJ, 1:3) = X(sub(1):sub(1)+tilesize-1, sub(2):sub(2)+tilesize-1, 1:3); %Compute the mask and write to the destination % M = zeros(tilesize, tilesize); % M(1:end, 1:overlap) = double(C == 0); % Y(startI:endI, startJ:endJ, :) = filtered_write(Y(startI:endI, startJ:endJ, :), ... % repmat(255, [tilesize, tilesize, 3]), M); end; %We have a top overlap if( i > 1 ) %Compute the SSD in the border region E = ( X(sub(1):sub(1)+overlap-1, sub(2):sub(2)+tilesize-1) - Y(startI:startI+overlap-1, startJ:endJ) ).^2; %Compute the mincut array C = mincut(E, 1); %Compute the mask and write to the destination M(1:overlap, 1:end) = M(1:overlap, 1:end) .* double(C >= 0); %Y(startI:endI, startJ:endJ, :) = filtered_write(Y(startI:endI, startJ:endJ, :), ... % X(sub(1):sub(1)+tilesize-1, sub(2):sub(2)+tilesize-1, :), M); end; if( i == 1 && j == 1 ) Y(startI:endI, startJ:endJ, 1:3) = X(sub(1):sub(1)+tilesize-1, sub(2):sub(2)+tilesize-1, 1:3); else %Write to the destination using the mask Y(startI:endI, startJ:endJ, :) = filtered_write(Y(startI:endI, startJ:endJ, :), ... X(sub(1):sub(1)+tilesize-1, sub(2):sub(2)+tilesize-1, :), M); end; end; image(uint8(Y)); drawnow; end; end; figure; image(uint8(Y)); function y = myssd( x ) y = sum( x.^2 ); function A = filtered_write(A, B, M) for i = 1:3, A(:, :, i) = A(:,:,i) .* (M == 0) + B(:,:,i) .* (M == 1); end
...全文
464 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
内容概要:本文详细记录了对一个Android ARM64静态ELF文件中字符串加密机制的逆向分析过程。该ELF文件的所有字符串均被加密,无法通过常规strings命令或IDA直接识别。作者通过分析发现,加密字符串存储在.rodata段,其解密所需信息(包括密文地址、长度和16位密钥)保存在.data.rel.ro段的40字节描述符中。核心解密函数sub_10F408采用自反的双pass流密码算法,结合固定密钥KEY_TERM(由.data段24字节数据计算得出),实现字节级非线性、位置与长度相关的加密。文章还复现了完整的Python解密脚本,并揭示了该保护机制的本质为代码混淆而非强加密,最终成功批量解密全部956条字符串,暴露程序真实行为,如shell命令模板、设备标识篡改、网络重置等操作。此外,文中还提及未启用的自定义壳框架及其反dump设计。; 适合人群:具备逆向工程基础的安全研究人员、二进制分析人员及对ELF保护技术感兴趣的开发者。; 使用场景及目标:①学习ELF二进制中字符串加密的典型实现方式与逆向突破口;②掌握从结构识别、函数追踪到算法还原的完整逆向流程;③理解“绑定二进制”的完整性校验设计及其局限性;④实践编写IDAPython脚本自动化提取与解密敏感数据。; 阅读建议:此资源以实战案例驱动,不仅展示技术细节,更强调逆向思维与验证方法,建议读者结合IDA调试环境,逐步跟随文中步骤进行动态分析与算法验证,深入理解每一步的推理依据。

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧