Ask Your Question
0

convert mat type from a specific range pixel value?

asked 2016-12-02 00:04:11 -0500

gino0717 gravatar image

Hi, I get the depth camera and I want to do some floodfill(). My source image is CV_16S.I have to convert the mat to CV_8U for floodfill(). However, what I interested is only a small range of pixel value, says, the image input is [0,4096] but I only want [2000,3000] convert to [0,255].

I did some threshold and then convert it like:

src.convertTo( dis, CV_8U, 255.0/4096.0 );

I'm not sure whether it is right or wrong so I'm searching some ready-to-use function. I think normalize would do something but it seems that the boundary of source image connot be set up. thanks for any idea.

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
2

answered 2016-12-02 02:03:38 -0500

updated 2016-12-02 02:08:09 -0500

Here are the steps to follow!

  1. Threshold your input image in the Range 2000-3000;
  2. Convert To 8 bit using the new min max value like this

    double min=2000; double max=3000;

    src.convertTo( dis, CV_8U, 255.0/(max-min), -min);

edit flag offensive delete link more

Comments

thanks a lot!

gino0717 gravatar imagegino0717 ( 2016-12-04 19:43:19 -0500 )edit
1

answered 2016-12-02 00:53:44 -0500

pi-null-mezon gravatar image

updated 2016-12-07 00:50:09 -0500

Hi. You have selected right function for color transformation but lost bias value. For example if you want to make transformation from [min,max] to [0,255] you should call:

src.convertTo( dis, CV_8U, 255.0 / (max - min), min * 255.0 / (min - max) );

edit flag offensive delete link more

Comments

thanks a lot!

gino0717 gravatar imagegino0717 ( 2016-12-04 19:43:21 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-12-02 00:04:11 -0500

Seen: 601 times

Last updated: Dec 07 '16