描述:和其它图像操作一样,图像的乘法操作也是点对点的像素点进行操作
公式描述:O(i,j) = I1(i,j) * I2(i,j)
注意1:和其它操作一样输入图像之一也可以是一个常值(C),即 O(i,j) = I(i,j) * C
注意2:上下限问题和循环问题,对于支持循环的图像格式来说,就不存在超过上下限问题,输出的图像像素值不管是多大,它总在上下限的范围之内进行循环。
Code:
Similarity, showing a part of kernel function:
/** *Applies the image mult operator on the specified image arrays, with the specified offset and scale value *@param src1_1d The first source image as a pixel array *@param src2_1d The second source image as a pixel array *@param width width of the destination image in pixels *@param height height of the destination image in pixels *@param oset The offset value *@param scale The scale value *@return A pixel array containing the product of the two input images */
public int [] DoMult(int [] src1_1d, int [] src2_1d, int width, int height, float oset, float scale){ int place1 = -1; int place2 = -1; int src1rgb = 0; int src2rgb = 0; int result = 0; //Get size of image and make 1d_arrays d_w = width; d_h = height; dest_1d = new int[d_w*d_h]; boolean firstwider = false; boolean secondwider = false; int wrap; if (i1_w > d_w){ wrap = ((i1_w + 1) - d_w); firstwider = true; } else if (i2_w > d_w){ wrap = ((i2_w + 1) - d_w); secondwider = true; } else { wrap = 0; } //if you know there is no wrap around, you can save yourself some time if (wrap == 0) { for (int i=0; i< dest_1d. length ; i++){ src2rgb = src2_1d[i] & 0x000000ff; src1rgb = src1_1d[i] & 0x000000ff; result = (int) ((scale * ((float) src1rgb * (float) src2rgb )) + oset); //clip to 0 ... 255 if (result < 0){ result = 0; } else if (result > 255){ result = 255; } //create an int value for dest_1d dest_1d[i ] = 0xff000000 | (result + (result << 16) + (result << 8)); } return dest_1d; } else { for (int i=0; i< dest_1d. length ; i++){ //we might need to skip out some pixels which aren't in the overlap area if ((i %d_w ) == 0 ) { if ( i == 0 ){ place1 = 0; place2 = 0; } else if (secondwider) { place2 = place2 + wrap; place1 ++; } else { place1 = place1 + wrap; place2 ++; } } else{ place2 ++; place1 ++; } src2rgb = src2_1d[place2] & 0x000000ff; src1rgb = src1_1d[place1] & 0x000000ff; result = (int) ((scale * ((float) src1rgb * (float) src2rgb )) + oset); //clip to 0 ... 255 if (result < 0){ result = 0; } else if (result > 255){ result = 255; } //create an int value for dest_1d dest_1d[i ] = 0xff000000 | (result + (result << 16) + (result << 8)); } return dest_1d; } }
Input Image:C=3;
Output Image:
总结:这里举例说明的是利用常数值,这样能更好的说明乘法操作的实质性。