Java for ImageJ. How to convert an image from RGB to 8 bit using code?

淺唱寂寞╮ 提交于 2021-02-08 04:07:39

问题


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.

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.

EDIT: 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"?

To clarify, I am programming for ImageJ using Java.

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.

Thanks

EDIT: 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.


回答1:


Please try:

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

// ...

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


来源:https://stackoverflow.com/questions/23065325/java-for-imagej-how-to-convert-an-image-from-rgb-to-8-bit-using-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!