JH Labs قياس كمية للحد من عمق لون الصورة
-
15-11-2019 - |
سؤال
أحاول استخدام الكميين في
http://www.jhlabs.com/ip/filters/index.html
لتقليل عمق لون لقطة شاشة.
هنا هو رمز بسيط جدا: giveacodicetagpre.
ومع ذلك، ما أتركه هو:
img الأصلي:
iMG الكمي:
تحليل آخر للمشكلة يظهر أن صفيف Inpixels مليء بشكل غير صحيح؛ تم شغلها ثلاث مرات مع الثلث العلوي من الصورة الأصلية.
أي مؤشرات كيف يمكنني إصلاح ذلك؟
بالإضافة إلى ذلك، أي روابط جيدة + خوارزمية كمية سريعة في جافا؟ ما أبحث عنه هو خوارزمية ستأخذ صورة Type_int_bgr وتنتج صورة Type_int_bgr جديدة ولكن مع اختلاف أقل فعالية في بكسل، لذلك يمكن تنغوط بسهولة.
على سبيل المثال، إذا كان لدينا اثنين من وحدات البكالة في الصورة الأصلية، مع قيم مثل 255 و 255 و 234 وآخر مع قيمة مثل 255 و 255 و 236، يجب تحويلها إلى 255،255،240. هتافات
المحلول
The following example will convert your image correctly:
QuantizeFilter q = new QuantizeFilter();
int [] inPixels = new int[image.getWidth()*image.getHeight()*3];
int [] outPixels = new int[image.getWidth()*image.getHeight()*3];
image.getRaster().getPixels( 0, 0, image.getWidth(), image.getHeight(), inPixels );
q.quantize(inPixels, outPixels, image.getWidth(), image.getHeight(), 64, false, false);
WritableRaster raster = (WritableRaster) image.getData();
raster.setPixels(0,0,width,height,outPixels);
Also there is no reason to create the files implicitly, as ImageIO.write creates them automatically.
نصائح أخرى
I have had the same problem and its not the code you posted that's at fault it's the QuantizeFilter
class which doesn't go through all the pixels. You need to find this code part
if (!dither) {
for (int i = 0; i < count; i++)
outPixels[i] = table[quantizer.getIndexForColor(inPixels[i])];
and multiply count by 3.
Please note that this is only a a fix if the last 2 parameters are set to false.