• 将图像的代数中心转移到几何中心上


    function  k2  = CenPtran( k,m,n)
    %UNTITLED Summary of this function goes here
    %   Detailed explanation goes here
    centerGPos = cenP(k);
    centerGPos1 = [floor(m/2)+1,floor(n/2)+1];
    if mod(abs(centerGPos(1)-centerGPos1(1)),2) == 0 && mod(abs(centerGPos(2)-centerGPos1(2)),2) ==0
        k1 = zeros(m+abs(centerGPos(1)-centerGPos1(1)),n+abs(centerGPos(2)-centerGPos1(2)));
    elseif  mod((centerGPos(1)-centerGPos1(1)),2) == 0&&mod(abs(centerGPos(2)-centerGPos1(2)),2) ~=0
        k1 = zeros(m+abs(centerGPos(1)-centerGPos1(1)),n+abs(centerGPos(2)-centerGPos1(2))+1);
    elseif  mod((centerGPos(2)-centerGPos1(2)),2) ==0&&mod((centerGPos(1)-centerGPos1(1)),2) ~= 0
        k1 = zeros(m+abs(centerGPos(1)-centerGPos1(1))+1,n+abs(centerGPos(2)-centerGPos1(2)));
    else
        k1 = zeros(m+abs(centerGPos(1)-centerGPos1(1))+1,n+abs(centerGPos(2)-centerGPos1(2))+1);
    end
    [k1m k1n] = size(k1);
    if centerGPos(1)-centerGPos1(1)>= 0 && centerGPos(2)-centerGPos1(2)>=0
        for ki =1:m
            for kj =1:n
                k1(ki,kj) = k(ki,kj);              
            end
        end
    elseif centerGPos(1)-centerGPos1(1)<0 && centerGPos(2)-centerGPos1(2)==0
        for ki = (abs(centerGPos(1)-centerGPos1(1))+1):(abs(centerGPos(1)-centerGPos1(1))+m)
            for kj =1:k1n
                k1(ki,kj) = k(ki-abs(centerGPos(1)-centerGPos1(1)),kj);               
            end
        end
    elseif centerGPos(2)-centerGPos1(2)<0&&centerGPos(1)-centerGPos1(1)== 0
        for ki = 1:k1m
            for kj =( (abs(centerGPos(2)-centerGPos1(2)))+1):((abs(centerGPos(2)-centerGPos1(2)))+n)
                k1(ki,kj) = k(ki,kj-abs(centerGPos(2)-centerGPos1(2)));               
            end
        end
    elseif  centerGPos(1)-centerGPos1(1)<0&& centerGPos(2)-centerGPos1(2)>0 
         for ki = (abs(centerGPos(1)-centerGPos1(1))+1):(abs(centerGPos(1)-centerGPos1(1))+m)
            for kj =1:n
                k1(ki,kj) = k(ki-abs(centerGPos(1)-centerGPos1(1)),kj);               
            end
         end
    elseif centerGPos(1)-centerGPos1(1)>0&& centerGPos(2)-centerGPos1(2)<0 
            for ki =1:m
                for kj =( (abs(centerGPos(2)-centerGPos1(2)))+1):((abs(centerGPos(2)-centerGPos1(2)))+n)
                    k1(ki,kj) = k(ki,kj-abs(centerGPos(2)-centerGPos1(2)));               
                end
            end
    else
        for ki = (abs(centerGPos(1)-centerGPos1(1))+1):(abs(centerGPos(1)-centerGPos1(1))+m)
            for kj =( (abs(centerGPos(2)-centerGPos1(2)))+1):((abs(centerGPos(2)-centerGPos1(2)))+n)
                k1(ki,kj) = k(ki-abs(centerGPos(1)-centerGPos1(1)),kj-abs(centerGPos(2)-centerGPos1(2)));               
            end
        end
    end
    centerGPos2 = cenP(k1);
    x1 = centerGPos2(1)-floor(m/2);
    x2 = x1+2*floor(m/2);
    y1 =  centerGPos2(2)-floor(n/2);
    y2 = y1+2*floor(n/2);
    k2 = k1(x1:x2,y1:y2);
  • 相关阅读:
    【转】Android Touch事件传递机制解析
    通过Selector来设置按钮enable/unable状态的样式
    Android中的selector
    Android单元测试
    Android Lint简介
    制作高仿QQ的聊天系统(下)—— Adapter & Activity
    EditText的监听器和自定义回车事件
    监听Listview的滚动状态,是否滚动到了顶部或底部
    制作高仿QQ的聊天系统(上)—— 布局文件 & 减少过度绘制
    数据更新后让ListView自动滚动到底部
  • 原文地址:https://www.cnblogs.com/jiangnanrain/p/3271106.html
Copyright © 2020-2023  润新知