Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » tif image 16 bit. autolevel
tif image 16 bit. autolevel [message #32173] Fri, 29 April 2011 08:54 Go to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

Hello,

I have a trouble with load 16bit tiff image and set color/contrast auto-level.

Is possible in U++?

Thank you in advance!

[Updated on: Fri, 29 April 2011 08:55]

Report message to a moderator

Re: tif image 16 bit. autolevel [message #32175 is a reply to message #32173] Fri, 29 April 2011 10:12 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Ion

Is it a 16 bits per color image?

What do you mean with set color/contrast auto-level?


Best regards
Iñaki
Re: tif image 16 bit. autolevel [message #32178 is a reply to message #32173] Fri, 29 April 2011 11:02 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

tojocky wrote on Fri, 29 April 2011 08:54

Hello,

I have a trouble with load 16bit tiff image and set color/contrast auto-level.

Is possible in U++?

Thank you in advance!

Hi Ion,

Unfortunately, U++ doesn't support 16 bit tiffs at the moment, and even libtiff support is quite limited. Have a look at this thread about the same topic, there are some links to sites suggesting how to possibly overcome these limitations...

Best regards,
Honza
Re: tif image 16 bit. autolevel [message #32182 is a reply to message #32175] Fri, 29 April 2011 11:28 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

koldo wrote on Fri, 29 April 2011 11:12

Hello Ion

Is it a 16 bits per color image?

What do you mean with set color/contrast auto-level?


In Photoshop Exists possibility to change color/contrast level.

Thank you for quick response!
Re: tif image 16 bit. autolevel [message #32183 is a reply to message #32178] Fri, 29 April 2011 11:35 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

dolik.rce wrote on Fri, 29 April 2011 12:02

tojocky wrote on Fri, 29 April 2011 08:54

Hello,

I have a trouble with load 16bit tiff image and set color/contrast auto-level.

Is possible in U++?

Thank you in advance!

Hi Ion,

Unfortunately, U++ doesn't support 16 bit tiffs at the moment, and even libtiff support is quite limited. Have a look at this thread about the same topic, there are some links to sites suggesting how to possibly overcome these limitations...

Best regards,
Honza

Thank you for hint.

I tried to open the tif image in U++. it opened OK, but on I tried to change contrast with the method:

Image Contrast(const Image& img, int amount)

but the contrast was not so good.

Any hint are welcome!

Thank you for quick response!
Re: tif image 16 bit. autolevel [message #32184 is a reply to message #32175] Fri, 29 April 2011 11:52 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

and a screenshot:

index.php?t=getfile&id=3202&private=0
Re: tif image 16 bit. autolevel [message #32189 is a reply to message #32173] Fri, 29 April 2011 20:13 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
tojocky wrote on Fri, 29 April 2011 02:54


I have a trouble with load 16bit tiff image and set color/contrast auto-level.



There is no routine for that at the moment.

Should not be hard to do I think... but one would have to be sure about algorithm I guess.

Mirek
Re: tif image 16 bit. autolevel [message #32195 is a reply to message #32189] Sat, 30 April 2011 09:33 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Ion

In summary you can open the image right and set it in an Image. This is very good Smile.

About the algorithm I agree with Mirek. I have searched about Photoshop algorithm unsuccessfully, but it seems they change the contrast by spreading the color histogram by all the range. There is more than one way to do it.

Please send here a sample of an image before and after that effect and we can try to give you the function.


Best regards
Iñaki
Re: tif image 16 bit. autolevel [message #32202 is a reply to message #32195] Sat, 30 April 2011 18:07 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

koldo wrote on Sat, 30 April 2011 10:33

Hello Ion

In summary you can open the image right and set it in an Image. This is very good Smile.

About the algorithm I agree with Mirek. I have searched about Photoshop algorithm unsuccessfully, but it seems they change the contrast by spreading the color histogram by all the range. There is more than one way to do it.

Please send here a sample of an image before and after that effect and we can try to give you the function.


Thank you Koldo for help.

I will try to find a solution too!

I have attached a simple image in tif 16bits before and after autolevel.
Re: tif image 16 bit. autolevel [message #32203 is a reply to message #32202] Sat, 30 April 2011 18:21 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

May be interesting article with simple code how to get HSL.
http://www.codeproject.com/KB/GDI-plus/HSLColorSpace.aspx?ms g=917339
Re: tif image 16 bit. autolevel [message #32210 is a reply to message #32203] Sun, 01 May 2011 15:50 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Ion

Here are the images and their histograms. You see the second one more extended along the color range.

index.php?t=getfile&id=3206&private=0

If you can wait a couple of days I can prepare something.

Ah, your girlfriend is very pretty Smile.
  • Attachment: image.png
    (Size: 63.77KB, Downloaded 626 times)


Best regards
Iñaki
Re: tif image 16 bit. autolevel [message #32225 is a reply to message #32210] Mon, 02 May 2011 09:30 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

koldo wrote on Sun, 01 May 2011 16:50

Hello Ion

Here are the images and their histograms. You see the second one more extended along the color range.

index.php?t=getfile&id=3206&private=0

If you can wait a couple of days I can prepare something.

Ah, your girlfriend is very pretty Smile.


Koldo,

It is exact What I need.
Can you share with code?

P.S. This is not my girlfriend. I'm married and you can see more photos by address: https://picasaweb.google.com/ionlupascu

[Updated on: Mon, 02 May 2011 09:34]

Report message to a moderator

Re: tif image 16 bit. autolevel [message #32228 is a reply to message #32225] Mon, 02 May 2011 10:17 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
A handsome couple! Smile

Best regards
Iñaki
Re: tif image 16 bit. autolevel [message #32229 is a reply to message #32228] Mon, 02 May 2011 10:30 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

koldo wrote on Mon, 02 May 2011 11:17

A handsome couple! Smile


Thank you!
Re: tif image 16 bit. autolevel [message #32232 is a reply to message #32229] Mon, 02 May 2011 12:03 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

OK, Now I'm able to print the histogram!

before autolevel:
index.php?t=getfile&id=3210&private=0

and after autolevel:
index.php?t=getfile&id=3211&private=0

and the algorithm:
	
	Vector<XY> hist_data;
	for(int i=0;i<256;++i)
		hist_data << XY(i, 0);
	
	const RGBA *s = ~img;
	const RGBA *e = s + img.GetLength();
	while(s < e) {
		v_curr_value = (s->r+s->g+s->b)/3;
		hist_data[v_curr_value].y++;
		if(hist_data[v_curr_value].y>v_max_y)
			v_max_y = hist_data[v_curr_value].y;
		s++;
	}


The easy way remain how to compute the autolevel algorithm in base of histogram!
Re: tif image 16 bit. autolevel [message #32233 is a reply to message #32232] Mon, 02 May 2011 14:02 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Ion

In your case to pass from one histogram to the other is as easy as multiplying any pixel by a factor.

In a more complex scenario you should have to set a window of your histogram and determine which function to apply, like:

New color = F(Old color)

Remember to use function int Grayscale(const Color& c). The conversion to gray is more adequate Smile.

PD. The second histogram strange zeros seem to indicate that there is a problem in the conversion program.


Best regards
Iñaki

[Updated on: Mon, 02 May 2011 14:04]

Report message to a moderator

Re: tif image 16 bit. autolevel [message #32236 is a reply to message #32233] Mon, 02 May 2011 16:21 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

I thing this is what I look for:
http://en.wikipedia.org/wiki/Histogram_equalisation
I did a variant of autolevel, but I intend to modify by wikipedia specification.
Image ImageAutolevel(const Image& img){
	uint64 histogram[256];
	for(int i=0;i<256;++i)
		histogram[i]=0;
	
	const RGBA *start = img;
	const RGBA *s = start;
	const RGBA *e = s + img.GetLength();
	while(s < e){
		histogram[(s->r+s->g+s->b)/3]++;
		s++;
	}
	int v_lower = -1;
	int v_upper = -1;
	
	for(int i=0;i<256&&(v_lower==-1||v_upper==-1);++i){
		if(v_lower==-1&&histogram[i]!=0)
			v_lower = i;
		if(v_upper==-1&&histogram[255-i]!=0)
			v_upper = 255-i;
	}
	
	// return if not sense to autolevel
	//if(v_lower==v_upper==-1)
	
	if(v_lower==-1)
		v_lower = 0;
	
	if(v_upper==-1)
		v_upper = 255;
	
	s = start;
	ImageBuffer w(img.GetSize());
	Unmultiply(w);
	RGBA *t = w;
	
	while(s < e) {
		t->r = s->r*255/v_upper;
		t->g = s->g*255/v_upper;
		t->b = s->b*255/v_upper;
		t->a = s->a;
		t++;
		s++;
	}
	Premultiply(w);
	w.SetHotSpots(img);
	return w;
}
Re: tif image 16 bit. autolevel [message #32237 is a reply to message #32236] Mon, 02 May 2011 17:37 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Ion

Your code is right, although consider this fragment:

index.php?t=getfile&id=3213&private=0

It is better to convert your original image from RGB to HSV, apply the algorithm to the Luminance component and convert the result to RGB.

In U++ we have the functions RGBtoHSV() and HSVtoRGB().
  • Attachment: pan.PNG
    (Size: 12.21KB, Downloaded 610 times)


Best regards
Iñaki
Re: tif image 16 bit. autolevel [message #32275 is a reply to message #32237] Thu, 05 May 2011 20:10 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

koldo wrote on Mon, 02 May 2011 18:37

Hello Ion

Your code is right, although consider this fragment:

index.php?t=getfile&id=3213&private=0

It is better to convert your original image from RGB to HSV, apply the algorithm to the Luminance component and convert the result to RGB.

In U++ we have the functions RGBtoHSV() and HSVtoRGB().


Thank you Koldo! I will!
Re: tif image 16 bit. autolevel [message #32276 is a reply to message #32275] Thu, 05 May 2011 20:15 Go to previous messageGo to previous message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

I finally get the wanted result! Was able to read true 16bit tiff image, set autolevel and after that converted in 8bit Image.

The result is like in Photoshop.
index.php?t=getfile&id=3221&private=0

It seems that equalization and autolevel a 2 different algorithms.

If somebody want, I can share the code!

[Updated on: Thu, 05 May 2011 20:17]

Report message to a moderator

Previous Topic: Printing a Layout
Next Topic: new! ANTI VIRUS FALSE POSITIVE with Upp (GUI MT FileSel)
Goto Forum:
  


Current Time: Thu Mar 28 17:36:05 CET 2024

Total time taken to generate the page: 0.01531 seconds