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

📄 scalablecolor.java

📁 图像检索的代码b
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

            {
                1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, 7, 9, 11,
                13, 15, 1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, 7,
                9, 11, 13, 15, 1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, 7, 9, 11, 13, 15, 1, 3,
                5, 7, 9, 11, 13, 15, 1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, 7, 9, 11, 13, 15,
                1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, 7, 9, 11,
                13, 15, 1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, 7, 9, 11, 13, 15, 0, 2, 4, 6,
                8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14, 0, 2,
                4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,
                0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10,
                12, 14, 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6,
                8, 10, 12, 14, 2, 6, 10, 14, 2, 6, 10, 14, 2, 6, 10, 14, 2, 6, 10, 14, 0, 4,
                8, 12, 0, 4, 8, 12, 0, 4, 8, 12, 4, 12, 8
            },

            {
                0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,
                2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5,
                5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8,
                8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
                11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13,
                13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 1, 1, 1, 1,
                1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 7, 7,
                7, 7, 7, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11, 11, 11, 11,
                13, 13, 13, 13, 13, 13, 13, 13, 15, 15, 15, 15, 15, 15, 15, 15, 4, 4, 4, 4, 4, 4,
                4, 4, 6, 6, 6, 6, 6, 6, 6, 6, 12, 12, 12, 12, 12, 12, 12, 12, 14, 14, 14, 14,
                14, 14, 14, 14, 0, 0, 0, 0, 2, 2, 2, 2, 8, 8, 8, 8, 10, 10, 10, 10, 2, 2,
                2, 2, 10, 10, 10, 10, 8, 8, 8, 8, 0, 0, 0
            },

            {
                128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
                128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
                128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
                128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
                128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
                128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
                128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
                128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
                128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
                128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
                128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
                128, 128, 128, 128, 128, 128, 128, 64, 64, 64, 64,
                64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
                64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
                64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 32, 32, 32, 32, 32, 32,
                32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
                32, 32, 32, 32, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 8, 8,
                8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 2, 2, 1
            }
        }
                ;

        int[] sorttab = {
            0, 8, 12, 4, 140, 136, 132, 128, 172,
            168, 164, 160, 44, 40, 36, 32,
            174, 170, 166, 162, 142, 138, 134, 130, 46,
            42, 38, 34, 14, 10, 6, 2,
            238, 236, 234, 232, 230, 228, 226, 224, 206,
            204, 202, 200, 198, 196, 194, 192,
            110, 108, 106, 104, 102, 100, 98, 96, 78,
            76, 74, 72, 70, 68, 66, 64,
            254, 252, 250, 248, 246, 244, 242, 240, 222,
            220, 218, 216, 214, 212, 210, 208,
            190, 188, 186, 184, 182, 180, 178, 176, 158,
            156, 154, 152, 150, 148, 146, 144,
            126, 124, 122, 120, 118, 116, 114, 112, 94,
            92, 90, 88, 86, 84, 82, 80,
            62, 60, 58, 56, 54, 52, 50, 48, 30,
            28, 26, 24, 22, 20, 18, 16,
            255, 253, 251, 249, 247, 245, 243, 241, 239,
            237, 235, 233, 231, 229, 227, 225,
            223, 221, 219, 217, 215, 213, 211, 209, 207,
            205, 203, 201, 199, 197, 195, 193,
            191, 189, 187, 185, 183, 181, 179, 177, 175,
            173, 171, 169, 167, 165, 163, 161,
            159, 157, 155, 153, 151, 149, 147, 145, 143,
            141, 139, 137, 135, 133, 131, 129,
            127, 125, 123, 121, 119, 117, 115, 113, 111,
            109, 107, 105, 103, 101, 99, 97,
            95, 93, 91, 89, 87, 85, 83, 81, 79,
            77, 75, 73, 71, 69, 67, 65,
            63, 61, 59, 57, 55, 53, 51, 49, 47,
            45, 43, 41, 39, 37, 35, 33,
            31, 29, 27, 25, 23, 21, 19, 17, 15,
            13, 11, 9, 7, 5, 3, 1
        }
                ;

        h_size = 16;
        s_size = 4;
        v_size = 4;
        hist_nr = 256;

        hist_nr = 256;

        RecHistogram = 0;

        histogram_in = new int[max_color];
        histogram_out = new int[max_color];

        for (int i = 0; i < NumberOfCoefficients; i++) {
            histogram_in[i] = (int) aHist[i];
        }

        if (RecHistogram == 2) {
            histo_3d_hirarch_16_5(tabelle, tablae, histogram_in, h_size, s_size, v_size, hist_nr);
            hsv_hir_quant_lin_5(histogram_in);
        }

        if (RecHistogram != 2) {
            histo_3d_hirarch_5(tabelle, tablae, histogram_in,
                    h_size, s_size, v_size, hist_nr);

            for (int j = 0; j < 256; ++j) {
                index = sorttab[j];
                histogram_out[j] = histogram_in[index];
            }

            hsv_hir_quant_lin_5(histogram_out);
            red_bits_pro_bin_5(histogram_out, NumberOfBitplanesDiscarded, 0);

        }
        int[] returnHist = new int[hist_nr];
        System.arraycopy(histogram_out, 0, returnHist, 0, hist_nr);

        return returnHist;

    }

    // XM Kauderwelsch :)
    void red_bits_pro_bin_5(
            int[] histogram,
            int NumberOfBitplanesDiscarded,
            int ivert) {
        int wert,wert1,bits_pro_bin,bits_pro_bild;
        int max_bits_pro_bin,anzkof;
        if (NumberOfBitplanesDiscarded == 0) return;

        bits_pro_bild = 0;
        max_bits_pro_bin = 0;
        anzkof = 0;
        if (NumberOfBitplanesDiscarded > 0) {
            for (int i = 0; i < 256; ++i) {
                bits_pro_bin = scalableColorQuantValues[i][1] - NumberOfBitplanesDiscarded;
                if (bits_pro_bin < 2) {
                    wert = histogram[i];
                    if (wert >= 0) histogram[i] = 0;
                    if (wert < 0) histogram[i] = 1;
                    bits_pro_bild = bits_pro_bild + 1;
                }
                if (bits_pro_bin >= 2) {
                    wert = histogram[i];
                    wert1 = wert;
                    if (wert < 0) wert = -wert;
                    bits_pro_bild = bits_pro_bild + bits_pro_bin;
                    if (bits_pro_bin > max_bits_pro_bin) max_bits_pro_bin = bits_pro_bin;
                    anzkof = anzkof + 1;

                    for (int j = 0; j < NumberOfBitplanesDiscarded; ++j)
                        wert = wert >> 1;

                    if ((wert == 0) && (wert1 >= 0)) histogram[i] = 0;
                    if ((wert == 0) && (wert1 < 0)) histogram[i] = 1;
                    if (wert > 0) {
                        if (wert1 < 0) wert = -wert;
                        histogram[i] = wert;
                    }
                }
            }
        }
    }

    // XM Kauderwelsch :)
    private void hsv_hir_quant_lin_5(
            int[] histogram) {
        int i,wert,maxwert;
        for (i = 0; i < 256; ++i) {
            maxwert = scalableColorQuantValues[i][2];
            wert = histogram[i] - scalableColorQuantValues[i][0];
            if (wert > maxwert) wert = maxwert;
            if (wert < -maxwert) wert = -maxwert;
            histogram[i] = wert;
        }
    }

    public int getNumberOfCoefficients() {
        return NumberOfCoefficients;
    }

    public void setNumberOfCoefficients(int numberOfCoefficients) {
        if (img!=null) {
            NumberOfCoefficients = numberOfCoefficients;
        }
    }

    public int getNumberOfBitplanesDiscarded() {
        return NumberOfBitplanesDiscarded;
    }

    public void setNumberOfBitplanesDiscarded(int numberOfBitplanesDiscarded) {
        if (img!=null) {
            NumberOfBitplanesDiscarded = numberOfBitplanesDiscarded;
        }
    }

    public int[] getHaarTransformedHistogram() {
        return haarTransformedHistogram;
    }

    public boolean isRecalcable() {
        if (_wholeHist!=null) {
            return true;
        }
        else {
            return false;
        }
    }

    public Element getDescriptor() {
        /*
          <VisualDescriptor xsi:type="ScalableColorType" numOfBitplanesDiscarded="1" numOfCoeff="16">
	        <Coeff>2 0 12 3 1</Coeff>
		  </VisualDescriptor>
        */
        Namespace mpeg7, xsi;
        mpeg7 = Namespace.getNamespace("", "urn:mpeg:mpeg7:schema:2001");
        xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");

        Element vdesc = new Element("VisualDescriptor", mpeg7).setAttribute("type", "ScalableColorType", xsi);
        vdesc.setAttribute("numOfBitplanesDiscarded", "" + NumberOfBitplanesDiscarded);
        vdesc.setAttribute("numOfCoeff", "" + NumberOfCoefficients);

        Element coeff = new Element("Coeff", mpeg7);
        vdesc.addContent(coeff);

        StringBuffer buff = new StringBuffer();
        for (int i = 0; i < NumberOfCoefficients; i++) {
            buff.append(haarTransformedHistogram[i] + " ");
        }

        coeff.setText(buff.toString().trim());

        return vdesc;
    }

//    public static void main(String[] args) {
//        ScalableColor c1, c2, c3, c4;
//        try {
//            System.out.println("creating DS from test1.jpg");
//            c1 = new ScalableColor(ImageIO.read(new File("test1.jpg")));
//            System.out.println("creating DS from test2.jpg");
//            c2 = new ScalableColor(ImageIO.read(new File("test2.jpg")));
//            System.out.println("creating DS from test3.jpg");
//            c3 = new ScalableColor(ImageIO.read(new File("test3.jpg")));
//            System.out.println("creating DS from test4.jpg");
//            c4 = new ScalableColor(ImageIO.read(new File("test4.jpg")));
//            System.out.println("compare c1-c1: " + c1.getSimilarity(c1));
//            System.out.println("compare c1-c2: " + c1.getSimilarity(c2));
//            System.out.println("compare c1-c3: " + c1.getSimilarity(c3));
//            System.out.println("compare c1-c4: " + c1.getSimilarity(c4));
//            System.out.println("compare c2-c3: " + c2.getSimilarity(c3));
//            System.out.println("compare c2-c4: " + c2.getSimilarity(c4));
//            System.out.println("compare c3-c4: " + c3.getSimilarity(c4));
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
}

⌨️ 快捷键说明

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