Read each pixel and neighbours with Image.pixelColor()

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
LiloLilo

Read each pixel and neighbours with Image.pixelColor()

Post by LiloLilo »

Hi,

I need to access each pixel of an image one by one, from left to right, top to bottom. For each pixel, I need to read the pixel itself, the left neighbour and the top one, do some calculations, store the result on another image, and then go on with the next. Is there any solution better than read each pixel one by one with Image.pixelColor()? May a pixel cache improve performances? I am using Magick++ with Visual C++ 8.0

thank you for help.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Read each pixel and neighbours with Image.pixelColor()

Post by anthony »

For best results, read two rows of image pixels and process them. Before moving to the next row. This will reduce your image cache handling, and even make it posible to later convert the script into a 'pipelined image handling' program (like "stream").
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
LiloLilo

Re: Read each pixel and neighbours with Image.pixelColor()

Post by LiloLilo »

anthony wrote:For best results, read two rows of image pixels and process them. Before moving to the next row. This will reduce your image cache handling, and even make it posible to later convert the script into a 'pipelined image handling' program (like "stream").
OK, but in this case every row will be read twice. Do you mean that image cache will be smart enaught to detect that one row is already there and this will avoid to read it from the image. But how this will produce a benefit? I won't need to write back the row, because of it will be written to another image.

Thank you for help.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Read each pixel and neighbours with Image.pixelColor()

Post by anthony »

You can always use two image caches one for each row. That way you only need to read each row once.
You will however have to ask Magick about have two caches simultaneously.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply