我正在尝试使用RGB值比较两个图像。
以下代码为未经过滤和过滤的相同RGB值提取。我希望这两个图像的值不同。 (未经过滤和过滤先前已定义)。这个想法是两个图像之间的差异越大(过滤之前和之后),过滤后的图像越差。
根据我的结果,我希望有两组不同的RGB值(1表示未过滤,1表示过滤)。我得到两组RGB值,但两者都是相同的。
我正在创建一个色盲模拟器,并希望比较两者的值。下面是一个" Normal"视觉形象和"色盲"视觉形象。
Unfiltered Image | Filtered Image
filteredImage = unfilteredImage = Img;
...
ImageDisplay = new JLabel(new ImageIcon(filteredImage));
...
private void TypeButtonPressed()
{
filteredImage(GetType());
}
...
int GetType()
{
int type = 0;
for (int i=0; i<numberOfTypes; i++)
{
JToggleButton TypeButton = TypeButtons[i];
if (TypeButton.isSelected()) type = i;
}
TypeListener.SetType(type);
return type;
}
...
BufferedImage unfiltered = unfilteredImage;
BufferedImage filtered = filteredImage;
//unfilteredImage
int ufwidth = unfiltered.getWidth();
int ufheight = unfiltered.getHeight();
Color unfilteredRGBValue = new Color(unfiltered.getRGB(ufwidth / 2, ufheight / 2));
int ufred = unfilteredRGBValue.getRed();
int ufgreen = unfilteredRGBValue.getGreen();
int ufblue = unfilteredRGBValue.getBlue();
System.out.println("Unfiltered Red: " + ufred);
System.out.println("Unfiltered Green: " + ufgreen);
System.out.println("Unfiltered Blue: " + ufblue);
System.out.println("Unfiltered Score: " + ufred + ufgreen + ufblue);
//filteredImage
int fwidth = filtered.getWidth();
int fheight = filtered.getHeight();
Color filteredRGBValue = new Color(filtered.getRGB(fwidth / 2, fheight / 2));
int fred = filteredRGBValue.getRed();
int fgreen = filteredRGBValue.getGreen();
int fblue = filteredRGBValue.getBlue();
System.out.println("Filtered Red: " + fred);
System.out.println("Filtered Green: " + fgreen);
System.out.println("Filtered Blue: " + fblue);
System.out.println("Filtered Score: " + fred + fgreen + fblue);
谢谢!
版
答案 0 :(得分:1)
你在这里做的是拍摄图像中心的一个像素的颜色:
<form name="myform" ng-submit="formSubmit()" novalidate>
<input ng-model="fields.name.title"
placeholder="Enter your name" name="username" type="text" required>
<span ng-show="myform.username.$error.required && !myform.username.$pristine">Invalid name</span>
<drop-down data="fields.levels" func='levelHandler'></drop-down>
<drop-down data="fields.stages" func='levelHandler'></drop-down>
<drop-down data="fields.colors" func='levelHandler'></drop-down>
<button type="submit">Submit Form</button>
</form>
如果我们查看Color unfilteredRGBValue = new Color(unfiltered.getRGB(ufwidth / 2, ufheight / 2))
方法的javadoc,它会说
使用此方法时,返回数据中的每个颜色分量只有8位精度。
我认为8位是一个非常小的精度,因为jpeg格式的标准RGB图像每像素有24位。可能两个图像中的中间像素不是那么明显。
答案 1 :(得分:1)
您的代码看起来很可疑
filteredImage = unfilteredImage = Img;
要正确读取图像,我需要看
BufferedImage bim1=null, bim2=null;
try {
bim1=ImageIO.read(new File("c:/..../image1.png"));
bim2=ImageIO.read(new File("c:/..../image2.png"));
}
catch (Exception ex) { ex.printStackTrace(); }