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?".
Iam a newbie to Image Magick. Iam tryin to use NewPixelRegionIterator in my program to grab a subregion from an image and has to print the pixel values of that region only.. My Code is ..
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
For example, if the original image is 640x480 and the subimages are 100x100, you can get 6 complete images along the width and 4 along the height for a total of 24 complete 100x100 sub-images.
But (640*480)/(100*100) is 30.
If you then call the function with a value of n greater than 23 it will fail one way or another.
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
For example, if the original image is 640x480 and the subimages are 100x100, you can get 6 complete images along the width and 4 along the height for a total of 24 complete 100x100 sub-images.
But (640*480)/(100*100) is 30.
If you then call the function with a value of n greater than 23 it will fail one way or another.
Pete
Thanks..for suggestion..for now iam just tryin to do for 15x15 image with 5x5 as sub image size. Am i using the newpixelregioniterator and PixelGetNextIteratorRow in the right way...?
I just spent the weekend looking at MagickWand source (research for IMv7 CLI redevelopment)
And while I have not coded in MagickWand (yet), I am familiar with it, and how IM programming works.
I believe you should be looping using a while() around PixelGetNextIteratorRow()
The row that is being processed can be retrieved with PixelGetIteratorRow(),
however what you are doing should work fine.
However the pixel in the row 'x' is handled as a value from 0 to region width, and not as a column number as you have.
That last would be the reason for the segmentation fault!
Finally you can't initialise new variables after your initial 'for' loops unless you start a new {...} block! That should be a compile time syntax error!
anthony wrote:I just spent the weekend looking at MagickWand source (research for IMv7 CLI redevelopment)
And while I have not coded in MagickWand (yet), I am familiar with it, and how IM programming works.
I believe you should be looping using a while() around PixelGetNextIteratorRow()
The row that is being processed can be retrieved with PixelGetIteratorRow(),
however what you are doing should work fine.
However the pixel in the row 'x' is handled as a value from 0 to region width, and not as a column number as you have.
That last would be the reason for the segmentation fault!
Finally you can't initialise new variables after your initial 'for' loops unless you start a new {...} block! That should be a compile time syntax error!
Your original for loops are closer to what you need but you are addressing the pixels array incorrectly.
When you call NewPixelRegionIterator it returns a linear array of sbimg_wdt pixels. You are addressing it as if it had returned a row from the whole image.
The for loop indices (especially of "x") need to be adjusted:
for (y=0; y<sbimg_hgt; y++) {
pixels = PixelGetNextIteratorRow(rg_itr, &sbimg_wdt);
for (x=0;x<sbimg_wdt; x++) {
red = (unsigned int) (255*PixelGetRed(pixels[x]));
green = (unsigned int) (255*PixelGetGreen(pixels[x]));
blue = (unsigned int) (255*PixelGetBlue(pixels[x]));
printf("At %ld,%ld, rgb : %d,%d,%d\n", x,y, red, green, blue);
}
printf("\n");
}
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
el_supremo wrote:Your original for loops are closer to what you need but you are addressing the pixels array incorrectly.
When you call NewPixelRegionIterator it returns a linear array of sbimg_wdt pixels. You are addressing it as if it had returned a row from the whole image.
The for loop indices (especially of "x") need to be adjusted:
If you want to write the prints back, modify the "pixels" array and then call PixelSyncIterator() appropriately.
just before the end of the 'y' loop.
However for any more complex work beyond straight pixel-by-pixel, that is convolutions or morphology type processing, I would probably go deeper and use MagickCore Pixel handling more directly.
Be warned however that MagickCore pixel handling has had major changes in IMv7 (mutli-channel), so stick with the more portable MagickWand if you can.