[Insight-users] How to sum pixels row-by-row?

Miller, James V (GE, Research) millerjv at crd.ge.com
Fri Feb 2 12:21:06 EST 2007


ITK does not provide a view of images as matrices.  Instead, ITK views images as "containers", similar to STL containers, and uses iterators to move about an N-dimensional image.
 
That being said, you can grab a pointer to the image buffer using the Image::GetBufferPointer() method.  I don't like to promote its use because I regret ever introducing it. Exposing the buffer pointer has made it difficult to introduce alternative memory organization schemes, such as images where only the pixels within a slice are contiguous in memory.
 
To could create a vnl wrapper around an itk image buffer, you can do the following 
 
vnl_matrix_ref<ImageType::PixelType> imgAsMatrix(img->GetBufferedRegion()->GetSize()[0], 
                                                                                img->GetBufferedRegion()->GetSize()[1], 
                                                                                img->GetBufferPointer());
 
As for summing the pixels in the rows or columns of an image, there is filter called itk::AccumulateImageFilter to do this.
 
Jim

________________________________

From: insight-users-bounces+millerjv=crd.ge.com at itk.org [mailto:insight-users-bounces+millerjv=crd.ge.com at itk.org] On Behalf Of Ali -
Sent: Friday, February 02, 2007 11:56 AM
To: Robert Tamburo
Cc: ITK
Subject: RE: [Insight-users] How to sum pixels row-by-row?



Perhaps this is not the most efficient way, is it possible to get the pointer to 
the image data and pass it to the matrix? If there is no such a class to convert 
images and matrices, then how is the vnl matrix class used in itk?!




	>> Can you tell me how it is possible to covert images to matrices and vice vera? 

	I'm not sure if there is an ITK class for this, but I imagine that you could:
	1. Instantiate a vnl matrix that is of the same size as your 2D image. 
	2. Iterate the image.
	3. As the iterator traverses the image, grab the pixel index and value.
	4. Set the pixel value in the matrix at the corresponding index.


	On Feb 2, 2007, at 11:15 AM, Ali - wrote:



		> 
		> > It is strange how ITK can perform so many elaborated image processings, 
		> > but it takes hours to figure out how to implement some elementary matrix 
		> > manipulations. I thought the inclusion of VXL in ITK means having a fast 
		> > MATLAB-style image processing toolkit in c++.
		> 
		> That's right that many filters are missing to perform simple tasks.
		> ITK is open source, and open to contributions. Feel free to contribute 
		> contribute new code to the insight journal :-)
		
		Even if the community provides it, I think it is not a good idea to 
		create a 'database' of all operations for images and I have at least 2 reasons for that.
		 
		First, it is really hard to find out which class does what operation simply by guessing 
		from its name. Secondly, not all the operations can be created as a linear combination 
		of the simple operations. This means you have to write filters forever, many of them may be 
		used only once.
		
		For example, the slice-by-slice filter you provides does not accept binary filters 
		to operate on each slice. So, if I want to divide an N x N image A to a 1 x N image B 
		row-by-row, I have to modify the slice-by-slice filter. In the matrix form, this can be 
		down simply by 'literally' one line: B->GetTranspose() * A. 
		
		Can you tell me how it is possible to covert images to matrices and vice vera? I know ITK 
		uses VNL matrices but I cannot see where this is used to maniplulate image pixels directly. 
		If this can be done, we won't need hundereds of image operation classes.
		
		> 
		> Gaetan
		> 
		> 
		> 
		> -- 
		> Gaëtan Lehmann
		> Biologie du Développement et de la Reproduction
		> INRA de Jouy-en-Josas (France)
		> tel: +33 1 34 65 29 66 fax: 01 34 65 29 09
		> http://voxel.jouy.inra.fr
		
		
________________________________

		Personalize your Live.com homepage with the news, weather, and photos you care about. Try it! <http://www.live.com/getstarted.aspx?icid=T001MSN30A0701>  
		_______________________________________________
		Insight-users mailing list
		Insight-users at itk.org
		http://www.itk.org/mailman/listinfo/insight-users



________________________________

Live Search: Better results, fast Try it now! <http://get.live.com/search/overview>  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070202/5ddcc285/attachment.htm


More information about the Insight-users mailing list