Ask Your Question
0

converting Lab to RGB

asked 2018-12-09 05:45:36 -0600

manef gravatar image

updated 2018-12-09 05:46:22 -0600

I'm using opencv 3.4.0 and android-studio, I want to apply CLAHE on the L channel so i used the Lab color space, but after applying CLAHE on th L channel i and last i converted the image back to RGB color space but i got this error whil trying to display the image. this is the error :

CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.0-dev) ../../modules/imgproc/src/color.cpp:11207: error: (-215) scn == 3 && (dcn == 3 || dcn == 4) &&



L = new Mat(newImage.rows(), newImage.cols(), CvType.CV_8UC(1));
a = new Mat(newImage.rows(), newImage.cols(), CvType.CV_8UC(1));
b = new Mat(newImage.rows(), newImage.cols(), CvType.CV_8UC(1));

BGR_RGB = Utils.loadResource(getApplicationContext(), R.drawable.retinalimage, CvType.CV_32FC3); 
Imgproc.cvtColor(BGR_RGB, newImage, Imgproc.COLOR_BGR2RGB);
Imgproc.cvtColor(newImage,newImage,Imgproc.COLOR_RGB2Lab);
split(newImage,Lab);
L = Lab.get(0);
a = Lab.get(1);
b = Lab.get(2);

CLAHE ce = Imgproc.createCLAHE();
ce.setClipLimit(2);
ce.setTilesGridSize(new Size(8, 8));
ce.apply(L, L);

Lab.add(0,L);
Core.merge(Lab,newImage);
Imgproc.cvtColor(newImage,newImage,Imgproc.COLOR_Lab2RGB);
showImage(newImage);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-12-09 06:17:12 -0600

berak gravatar image

updated 2018-12-09 06:19:08 -0600

CvType.CV_32FC3 is the wrong type to load it, you don't need the RGB conversion, and you should not add a new channel at the end. try like this:

Mat bgr = Utils.loadResource(getApplicationContext(), R.drawable.retinalimage, CvType.CV_8UC3); 
Mat newImage = new Mat();
Imgproc.cvtColor(bgr, newImage, Imgproc.COLOR_BGR2Lab,3);

java.util.List<Mat> Lab = new ArrayList<Mat>();
Core.split(newImage,Lab);
Mat L = Lab.get(0); // L,a,b are references, not copies
Mat a = Lab.get(1);
Mat b = Lab.get(2);

CLAHE ce = Imgproc.createCLAHE();
ce.setClipLimit(2);
ce.setTilesGridSize(new Size(8, 8));
ce.apply(L, L);

Core.merge(Lab,newImage);
Imgproc.cvtColor(newImage,bgr,Imgproc.COLOR_Lab2RGB); // maybe it needs bgr here, too.
edit flag offensive delete link more

Comments

1

it worked thanks a lot, the problem was in the Lab.add(0,L); as you said it reference so I don't need to add it, if i add it the Lab become 4 channels not 3, thanks again

manef gravatar imagemanef ( 2018-12-09 06:23:20 -0600 )edit
1

so, you understood the error, great !

berak gravatar imageberak ( 2018-12-09 06:34:01 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-12-09 05:45:36 -0600

Seen: 2,950 times

Last updated: Dec 09 '18