用于 ImageJ 的 Java.如何使用代码将图像从 RGB 转换为 8 位? [英] Java for ImageJ. How to convert an image from RGB to 8 bit using code?

查看:423
本文介绍了用于 ImageJ 的 Java.如何使用代码将图像从 RGB 转换为 8 位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究连接组件标签.这是一个获取图像并告诉您图像中有多少独立对象的过程.

I am currently working on Connected Component Labelling. This is a process which takes an image and tells you how many separate objects are in the Image.

我的问题是,一开始我需要能够拍摄任何图像(特别是 RGB 值)并将其转换为 8 位.

My problem is that at the very start I need to be able to take any image (specifically RGB value) and convert it into 8-bit.

正如字面上认为的 8 位,图像不再被识别为 RGB.不是识别为 RGB 的 8 位图像.

as in literally considered an 8bit, where the image is no longer recognised as RGB. Not an 8bit image that is recognised as an RGB.

有没有办法使用代码自动执行此操作,而无需进入工具栏并手动"转换?

Is there a way using code to automatically do this without having to go into the toolbar and convert it "manually"?

澄清一下,我正在使用 Java 为 ImageJ 编程.

To clarify, I am programming for ImageJ using Java.

如果有人愿意帮助我,我很乐意向他们提供到目前为止我正在制作彩色图像灰度然后使其二进制化的代码.我的问题是,更改后图像仍被视为 RGB,即使图像本质上是 8 位.

If anyone is willing to help me, I would be happy to provide them with the code I have so far where I am making a coloured image grey scale and then making it binary. My problem is that after the changes the image is still considered RGB, even though the image is essentially 8 bit.

谢谢

我正在查看之前提供给我的代码,但它似乎没有解决我的问题.从字面上看,我只是想在 RGB 旁边做一个小勾",而不是在 8 位旁边.我已经自己完成了所有实际转换,它仍然被识别为RGB图像.

I was looking at the code provided to me earlier and it doesn't seem to solve my problem. I am quite literally just wanting to make the little 'tick' that's next to RGB, be next to 8-bit instead. I have already done all the actual conversion on my own, its just still recognised as RGB image.

推荐答案

请尝试:

import ij.ImagePlus;
import ij.process.ImageConverter;

// ...

ImagePlus imp = IJ.getImage();
ImageConverter ic = new ImageConverter(imp);
ic.convertToGray8();
imp.updateAndDraw();

这篇关于用于 ImageJ 的 Java.如何使用代码将图像从 RGB 转换为 8 位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆