
Hi, I am Paula, image processing student, and I am working with Olena. I have a doubt: I want to create a RGB image and I want to give each pixel a certain color. I do the following: image2d <value::rgb8> imagePrueb(rows,cols); fill(imagePrueb, literal::white); This way, the problem is the whole image has the same color... How can I set the desired color to each pixel? Thank you. Best regards. Paula.

On 03/09/2013 16:38, Paula Agregán Reboredo wrote:
Hi,
Hello,
I am Paula, image processing student, and I am working with Olena. I have a doubt: I want to create a RGB image and I want to give each pixel a certain color. I do the following:
image2d <value::rgb8> imagePrueb(rows,cols); fill(imagePrueb, literal::white);
This way, the problem is the whole image has the same color... How can I set the desired color to each pixel?
I am not fully sure about what you want to do here. Do you mean ``setting a particular color to a given pixel''? To do so, you can use the image's operator (), which gives an access to the value located at the point passed as argument. E.g., if you want to set the value located at row 42 and column 51 to the RGB value (255, 128, 0) (i.e. orange), use the following: using namespace mln; point2d p(42, 51); imagePrueb(p) = value::rgb8(255, 128, 0); You can also use the following shortcut which does the exact same operation: opt::at(imagePrueb, 42, 51) = value::rgb8(255, 128, 0); You can of course combine this with iterations on rows and colums, e.g.: /* The imagePrueb.domain() call returns the domain of the image imagePrueb, which is here a 2D box defined by two 2D points: the top left-hand corner, returned by imagePrueb.domain().pmin(), and the bottom right-hand corner, returned by imagePrueb.domain().pmax(). */ for (def::coord row = imagePrueb.domain().pmin().row(); row <= imagePrueb.domain().pmax().row(); ++row) for (def::coord col = imagePrueb.domain().pmin().col(); col <= imagePrueb.domain().pmax().col(); ++col) opt::at(imagePrueb, row, col) = f(row, col); where `f' is a function returning taking two coordinates as input and returning a value::rgb8; for instance: mln::value::rgb8 f(mln::def::coord row, mln::def::coord col) { return mln::value::rgb8(row % 256, col % 256, (row + col) % 256); } However, row- and column-wise iteration is not recommended to browse an image in Milena. The library provides domains and iterators to perform this task in a more concise and more generic fashion (that is, usable with other types of images): mln_piter_(image2d<rgb8>) p(imagePrueb.domain()); for_all(p) imagePrueb(p) = f(row, col); The code above does the same thing as the previous code using two for-loops. Hope this will help you. Best regards, Roland -- Roland Levillain EPITA Research and Development Laboratory (LRDE) 14-16, rue Voltaire - FR-94276 Le Kremlin-Bicêtre Cedex - France Phone: +33 1 53 14 59 45 - Fax: +33 1 53 14 59 22 - www.lrde.epita.fr
participants (2)
-
Paula Agregán Reboredo
-
Roland Levillain