@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.39 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import e from"../PixelBlock.js";import{convolutionKernel as t}from"../rasterFunctionConstants.js";import{mirror as n}from"./mirror.js";const l=new Map;function o(e){const t=Math.sqrt(e.length),n=e.slice(0,t),l=[1];for(let o=1;o<t;o++){let n=null;for(let l=0;l<t;l++){const r=e[l+o*t],s=e[l];if(null==n)if(0===s){if(r)return{separable:!1,row:null,col:null}}else n=r/s;else if(r/s!==n)return{separable:!1,row:null,col:null}}if(null==n)return{separable:!1,row:null,col:null};l.push(n)}return{separable:!0,row:n,col:l}}function r(e,t,n,l,o,r,s){const i=new Float32Array(t*n),a=r.length,h=s?0:l,c=s?l:0,p=s?1:t;for(let u=h;u<n-h;u++){const n=u*t;for(let s=c;s<t-c;s++){if(o&&!o[n+s])continue;let t=0;for(let o=0;o<a;o++)t+=e[n+s+(o-l)*p]*r[o];i[n+s]=t}}return i}function s(e,t,n,l,o,r,s){const i=new Float32Array(t*n),a=Math.floor(l/2),h=Math.floor(o/2);for(let c=a;c<n-a;c++){const n=c*t;for(let c=h;c<t-h;c++){if(r&&!r[n+c])continue;let p=0;for(let r=0;r<l;r++)for(let l=0;l<o;l++)p+=e[n+c+(r-a)*t+l-h]*s[r*o+l];i[n+c]=p}}return i}function i(t,l,o=!0){const{pixels:r,width:i,height:a,pixelType:h,mask:c}=t,p=r.length,u=[],{kernel:f,rows:g,cols:m}=l;for(let e=0;e<p;e++){const t=s(r[e],i,a,g,m,c,f);o&&n(t,i,a,g,m),u.push(t)}return new e({width:i,height:a,pixelType:h,pixels:u,mask:c})}function a(t,l,o,s=!0){const{pixels:i,width:a,height:h,pixelType:c,mask:p}=t,u=i.length,f=[],g=l.length,m=o.length,x=Math.floor(g/2),w=Math.floor(m/2);for(let e=0;e<u;e++){let t=r(i[e],a,h,x,p,l,!0);t=r(t,a,h,w,p,o,!1),s&&n(t,a,h,g,m),f.push(t)}return new e({width:a,height:h,pixelType:c,pixels:f,mask:p})}function h(e,t){const n=o(t.kernel),l=!1!==t.mirrorEdges,r=n.separable?a(e,n.row,n.col,l):i(e,t,l),{outputPixelType:s}=t;return s&&r.clamp(s),r}l.set(t.none,[0,0,0,0,1,0,0,0,0]),l.set(t.lineDetectionHorizontal,[-1,-1,-1,2,2,2,-1,-1,-1]),l.set(t.lineDetectionVertical,[-1,2,-1,-1,2,-1,-1,2,-1]),l.set(t.lineDetectionLeftDiagonal,[2,-1,-1,-1,2,-1,-1,-1,2]),l.set(t.lineDetectionRightDiagonal,[-1,-1,2,-1,2,-1,2,-1,-1]),l.set(t.gradientNorth,[-1,-2,-1,0,0,0,1,2,1]),l.set(t.gradientWest,[-1,0,1,-2,0,2,-1,0,1]),l.set(t.gradientEast,[1,0,-1,2,0,-2,1,0,-1]),l.set(t.gradientSouth,[1,2,1,0,0,0,-1,-2,-1]),l.set(t.gradientNorthEast,[0,-1,-2,1,0,-1,2,1,0]),l.set(t.gradientNorthWest,[-2,-1,0,-1,0,1,0,1,2]),l.set(t.smoothArithmeticMean,[.111111111111,.111111111111,.111111111111,.111111111111,.111111111111,.111111111111,.111111111111,.111111111111,.111111111111]),l.set(t.smoothing3x3,[.0625,.125,.0625,.125,.25,.125,.0625,.125,.0625]),l.set(t.smoothing5x5,[1,1,1,1,1,1,4,4,4,1,1,4,12,4,1,1,4,4,4,1,1,1,1,1,1]),l.set(t.sharpening3x3,[-1,-1,-1,-1,9,-1,-1,-1,-1]),l.set(t.sharpening5x5,[-1,-3,-4,-3,-1,-3,0,6,0,-3,-4,6,21,6,-4,-3,0,6,0,-3,-1,-3,-4,-3,-1]),l.set(t.laplacian3x3,[0,-1,0,-1,4,-1,0,-1,0]),l.set(t.laplacian5x5,[0,0,-1,0,0,0,-1,-2,-1,0,-1,-2,17,-2,-1,0,-1,-2,-1,0,0,0,-1,0,0]),l.set(t.sobelHorizontal,[-1,-2,-1,0,0,0,1,2,1]),l.set(t.sobelVertical,[-1,0,1,-2,0,2,-1,0,1]),l.set(t.sharpen,[0,-.25,0,-.25,2,-.25,0,-.25,0]),l.set(t.sharpen2,[-.25,-.25,-.25,-.25,3,-.25,-.25,-.25,-.25]),l.set(t.pointSpread,[-.627,.352,-.627,.352,2.923,.352,-.627,.352,-.627]);export{h as convolute,a as convoluteSeparable,l as convolutionKernels,o as separateKernels};