UNPKG

image-ms-ssim

Version:

Image multi-scale structural similarity (MS-SSIM). In TypeScript/JavaScript. For browser/server.

2 lines 3.94 kB
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.ImageMSSSIM=e()}}(function(){return function e(n,t,r){function i(o,h){if(!t[o]){if(!n[o]){var f="function"==typeof require&&require;if(!h&&f)return f(o,!0);if(a)return a(o,!0);var s=new Error("Cannot find module '"+o+"'");throw s.code="MODULE_NOT_FOUND",s}var l=t[o]={exports:{}};n[o][0].call(l.exports,function(e){var t=n[o][1][e];return i(t?t:e)},l,l.exports,e,n,t,r)}return t[o].exports}for(var a="function"==typeof require&&require,o=0;o<r.length;o++)i(r[o]);return i}({1:[function(e,n,t){var r,i=e("image-ssim"),a=e("image-resize-linear");!function(e){"use strict";function n(e,n,t,r,o,h,f){void 0===t&&(t=8),void 0===r&&(r=.01),void 0===o&&(o=.03),void 0===h&&(h=!0),void 0===f&&(f=8);var s=[.0448,.2856,.3001,.2363,.1333],l=[],d=[],c=[],u=[],v=e.width,w=e.height;c[0]=e,u[0]=n;for(var g=0;g<s.length;g++){var p=i.compare(c[g],u[g],t,r,o,h,f);l[g]=p.ssim,d[g]=p.mcs,g<s.length-1&&(v=Math.floor(v/2),w=Math.floor(w/2),c[g+1]={width:v,height:w,data:new Uint8Array(v*w*e.channels),channels:e.channels},u[g+1]={width:v,height:w,data:new Uint8Array(v*w*n.channels),channels:n.channels},a.linear(c[g],c[g+1]),a.linear(u[g],u[g+1]))}var m=l[s.length-1];for(g=0;g<s.length-1;g++)m*=Math.pow(d[g],s[g]);return{msssim:m,ssim:l[0]}}e.compare=n}(r||(r={})),n.exports=r},{"image-resize-linear":2,"image-ssim":3}],2:[function(e,n,t){var r;!function(e){"use strict";function n(e,n){for(var t,r,i,a,o,h,f,s,l,d,c,u,v,w,g,p,m=e.width<n.width?(e.width-1)/n.width:e.width/n.width,y=e.height<n.height?(e.height-1)/n.height:e.height/n.height,M=e.width*e.channels,x=e.width-1,A=e.height-1,G=0;G<n.height;G++)for(var b=0;b<n.width;b++){t=b*m,r=G*y,i=Math.floor(t),a=Math.floor(r),l=i*e.channels+a*M,d=l+(x>i?e.channels:0),c=l+(A>a?M:0),u=c+(x>i?e.channels:0),o=t-i,h=r-a,f=1-o,s=1-h,v=f*s,w=o*s,g=f*h,p=o*h;for(var B=0;B<e.channels;B++)n.data[(b+G*n.width)*e.channels+B]=v*e.data[l+B]+w*e.data[d+B]+g*e.data[c+B]+p*e.data[u+B]}}e.linear=n}(r||(r={})),n.exports=r},{}],3:[function(e,n,t){var r;!function(e){"use strict";function n(e,n,r,i,a,o,h){function f(e,n,t,r){var i,a,o;i=a=o=0;for(var h=0;h<e.length;h++)a+=Math.pow(e[h]-t,2),o+=Math.pow(n[h]-r,2),i+=(e[h]-t)*(n[h]-r);var f=e.length-1;a/=f,o/=f,i/=f;var s=(2*t*r+l)*(2*i+d),w=(Math.pow(t,2)+Math.pow(r,2)+l)*(a+o+d);u+=s/w,v+=(2*i+d)/(a+o+d),c++}if(void 0===r&&(r=8),void 0===i&&(i=.01),void 0===a&&(a=.03),void 0===o&&(o=!0),void 0===h&&(h=8),e.width!==n.width||e.height!==n.height)throw new Error("Images have different sizes!");var s=(1<<h)-1,l=Math.pow(i*s,2),d=Math.pow(a*s,2),c=0,u=0,v=0;return t._iterate(e,n,r,o,f),{ssim:u/c,mcs:v/c}}!function(e){e[e.Grey=1]="Grey",e[e.GreyAlpha=2]="GreyAlpha",e[e.RGB=3]="RGB",e[e.RGBAlpha=4]="RGBAlpha"}(e.Channels||(e.Channels={}));e.Channels;e.compare=n;var t;!function(e){function n(e,n,i,a,o){for(var h=e.width,f=e.height,s=0;f>s;s+=i)for(var l=0;h>l;l+=i){var d=Math.min(i,h-l),c=Math.min(i,f-s),u=t(e,l,s,d,c,a),v=t(n,l,s,d,c,a),w=r(u),g=r(v);o(u,v,w,g)}}function t(e,n,t,r,i,a){for(var o=e.data,h=new Float32Array(new ArrayBuffer(r*i*4)),f=0,s=t+i,l=t;s>l;l++){var d=l*e.width,c=(d+n)*e.channels,u=(d+n+r)*e.channels;switch(e.channels){case 1:for(;u>c;)h[f++]=o[c++];break;case 2:for(;u>c;)h[f++]=o[c++]*(o[c++]/255);break;case 3:if(a)for(;u>c;)h[f++]=.212655*o[c++]+.715158*o[c++]+.072187*o[c++];else for(;u>c;)h[f++]=o[c++]+o[c++]+o[c++];break;case 4:if(a)for(;u>c;)h[f++]=(.212655*o[c++]+.715158*o[c++]+.072187*o[c++])*(o[c++]/255);else for(;u>c;)h[f++]=(o[c++]+o[c++]+o[c++])*(o[c++]/255)}}return h}function r(e){for(var n=0,t=0;t<e.length;t++)n+=e[t];return n/e.length}e._iterate=n}(t||(t={}))}(r||(r={})),n.exports=r},{}]},{},[1])(1)}); //# sourceMappingURL=image-ms-ssim.min.js.map