⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arbroimaskgenerator.java

📁 jpeg2000算法实现
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                else if(rois[r].rect){ // Rectangular ROI                    x = rois[r].ulx;                    y = rois[r].uly;                    lrx = rois[r].w+x-1;                    lry = rois[r].h+y-1;                    if( (x>tileulx+tilew) || (y>tileuly+tileh) ||                        (lrx<tileulx) || (lry<tileuly) ) // Roi not in tile                        continue;                    roiInTile=true;                                        // Check bounds                    x   -= tileulx;                    lrx -= tileulx;                    y   -= tileuly;                    lry -= tileuly;                    x = (x<0) ? 0:x;                    y = (y<0) ? 0:y;                    w = (lrx > (tilew-1))? tilew-x:lrx+1-x;                    h = (lry > (tileh-1))? tileh-y:lry+1-y;                                                            i = (y+h-1)*tilew+x+w-1;                    maxj = w;                    wrap = tilew-maxj;                    for(k=h; k>0; k--){                        for(j=maxj; j>0; j--,i--){			    mask[i] = curScalVal;                        }                        i -= wrap;                    }                }                else{ // Non-rectangular ROI. So far only circular case                     cx = rois[r].x-tileulx;                    cy = rois[r].y-tileuly;                    rad = rois[r].r;                    i = tileh*tilew-1;                    for(k=tileh-1; k>=0; k--){                        for(j=tilew-1; j>=0; j--,i--){                            if(((j-cx)*(j-cx)+(k-cy)*(k-cy) < rad*rad)){                                mask[i] = curScalVal;                                roiInTile = true;                            }                        }                    }                }            }        }                 // If wavelet transform is used        if(sb.isNode) {            // Decompose the mask according to the subband tree            // Calculate size of padded line buffer            WaveletFilter vFilter = sb.getVerWFilter();            WaveletFilter hFilter = sb.getHorWFilter();            int lvsup =                 vFilter.getSynLowNegSupport()+vFilter.getSynLowPosSupport();            int hvsup =                 vFilter.getSynHighNegSupport()+vFilter.getSynHighPosSupport();            int lhsup =                 hFilter.getSynLowNegSupport()+hFilter.getSynLowPosSupport();            int hhsup =                 hFilter.getSynHighNegSupport()+hFilter.getSynHighPosSupport();            lvsup = (lvsup>hvsup)? lvsup:hvsup;            lhsup = (lhsup>hhsup)? lhsup:hhsup;            lvsup = (lvsup>lhsup)? lvsup:lhsup;            paddedMaskLine = new int[lineLen+lvsup];                        if(roiInTile)                decomp(sb,tilew,tileh,c);        }    }    /**      * This function decomposes the mask for a node in the subband tree.     * after the mask is decomposed for a node, this function is called for      * the children of the subband. The decomposition is done line by line     * and column by column     *     * @param sb The subband that is to be used for the decomposition     *     * @param tilew The width of the current tile     *     * @param tileh The height of the current tile     *     * @param c component number     */    private void decomp(Subband sb, int tilew, int tileh, int c){        int ulx = sb.ulx;        int uly = sb.uly;        int w = sb.w;        int h = sb.h;        int scalVal,maxVal = 0;        int i,j,k,s,hi,mi = 0,pin,li;        int hmax,lmax,smax;        int wrap,lineoffs,lastlow;        int[] mask = roiMask[c]; // local copy        int[] low = maskLineLow; // local copy        int[] high = maskLineHigh; // local copy        int[] padLine = paddedMaskLine; // local copy        int highFirst = 0;        int lastpin;        if(!sb.isNode)            return;        // HORIZONTAL DECOMPOSITION        // Calculate number of high and low samples after decomposition        // and get support for low and high filters        WaveletFilter filter = sb.getHorWFilter();        int lnSup = filter.getSynLowNegSupport();        int hnSup = filter.getSynHighNegSupport();        int lpSup = filter.getSynLowPosSupport();        int hpSup = filter.getSynHighPosSupport();        int lsup = lnSup+lpSup+1;        int hsup = hnSup+hpSup+1;        // Calculate number of high/low coeffis in subbands        highFirst = sb.ulcx%2;        if(sb.w%2==0){            lmax = w/2-1;            hmax = lmax;        }        else{            if(highFirst==0){                lmax = (w+1)/2-1;                hmax = w/2-1;            }            else{                hmax = (w+1)/2-1;                lmax = w/2-1;            }        }                    int maxnSup = (lnSup>hnSup) ? lnSup:hnSup; // Maximum negative support        int maxpSup = (lpSup>hpSup) ? lpSup:hpSup; // Maximum positive support        // Set padding to 0        for(pin=maxnSup-1;pin>=0;pin--)            padLine[pin] = 0;        for(pin=maxnSup+w-1+maxpSup;pin>=w;pin--)            padLine[pin] = 0;        // Do decomposition of all lines         lineoffs = (uly+h)*tilew+ulx+w-1;        for(j=h-1;j>=0;j--){            lineoffs -= tilew;            // Get the line to transform from the mask            mi=lineoffs;            for(k=w, pin=w-1+maxnSup ; k>0 ; k--,mi--,pin--){                padLine[pin] = mask[mi];            }            lastpin = maxnSup+highFirst+2*lmax+lpSup;            for(k=lmax; k>=0 ; k--,lastpin-=2){ // Low frequency samples                pin = lastpin;                for(s=lsup;s>0;s--,pin--){                    scalVal = padLine[pin];                    if(scalVal>maxVal)                        maxVal = scalVal;                }                low[k] = maxVal;                maxVal = 0;            }            lastpin = maxnSup-highFirst+2*hmax+1+hpSup;            for(k=hmax; k>=0 ; k--,lastpin-=2){ // High frequency samples                pin = lastpin;                for(s=hsup;s>0;s--,pin--){                    scalVal = padLine[pin];                    if(scalVal>maxVal)                        maxVal = scalVal;                }                high[k] = maxVal;                maxVal = 0;            }            // Put the lows and highs back            mi=lineoffs;            for(k=hmax; k>=0; k--,mi--){                mask[mi] = high[k];            }            for(k=lmax;k>=0;k--,mi--){                mask[mi] = low[k];            }        }                  // VERTICAL DECOMPOSITION        // Calculate number of high and low samples after decomposition        // and get support for low and high filters        filter = sb.getVerWFilter();        lnSup = filter.getSynLowNegSupport();                hnSup = filter.getSynHighNegSupport();        lpSup = filter.getSynLowPosSupport();        hpSup = filter.getSynHighPosSupport();        lsup = lnSup+lpSup+1;        hsup = hnSup+hpSup+1;        // Calculate number of high/low coeffs in subbands        highFirst = sb.ulcy%2;        if(sb.h%2==0){            lmax = h/2-1;            hmax = lmax;        }        else{            if(sb.ulcy%2==0){                lmax = (h+1)/2-1;                hmax = h/2-1;            }            else{                hmax = (h+1)/2-1;                lmax = h/2-1;            }        }                    maxnSup = (lnSup>hnSup) ? lnSup:hnSup; // Maximum negative support        maxpSup = (lpSup>hpSup) ? lpSup:hpSup; // Maximum positive support        // Set padding to 0        for(pin=maxnSup-1;pin>=0;pin--)            padLine[pin] = 0;        for(pin=maxnSup+h-1+maxpSup;pin>=h;pin--)            padLine[pin] = 0;        // Do decomposition of all columns         lineoffs=(uly+h-1)*tilew+ulx+w;        for(j=w-1;j>=0;j--){            lineoffs--;            // Get the line to transform from the mask            mi = lineoffs;            for(k=h, pin=k-1+maxnSup ; k>0 ; k--,mi-=tilew,pin--){                padLine[pin] = mask[mi];            }            lastpin=maxnSup+highFirst+2*lmax+lpSup;            for(k=lmax; k>=0 ; k--,lastpin-=2){ // Low frequency samples                pin = lastpin;                for(s=lsup;s>0;s--,pin--){                    scalVal = padLine[pin];                    if(scalVal>maxVal)                        maxVal = scalVal;                }                low[k] = maxVal;                maxVal = 0;            }            lastpin = maxnSup-highFirst+2*hmax+1+hpSup;            for(k=hmax; k>=0 ; k--,lastpin-=2){ // High frequency samples                pin = lastpin;                for(s=hsup;s>0;s--,pin--){                    scalVal = padLine[pin];                    if(scalVal>maxVal)                        maxVal = scalVal;                }                high[k] = maxVal;                maxVal = 0;            }            // Put the lows and highs back            mi=lineoffs;            for(k=hmax;k>=0;k--,mi-=tilew){                mask[mi] = high[k];            }            for(k=lmax;k>=0;k--,mi-=tilew){                mask[mi] = low[k];            }        }        if(sb.isNode){            decomp(sb.getHH(), tilew, tileh, c);            decomp(sb.getLH(), tilew, tileh, c);            decomp(sb.getHL(), tilew, tileh, c);            decomp(sb.getLL(), tilew, tileh, c);        }    }}       

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -