By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,908 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,908 IT Pros & Developers. It's quick & easy.

URGENT !!!! Image Patches & Image Cropping (c#)

P: 1
hi, I have been trying to generate image patches for a training set but have not succeded yet. The only method i tried is cropping areas of the image and store the cropped images or patches as an array of bytes. The problem is, same patch gets stored thoughout the array, meaning its cropping the same area in the loop and the rectangle is not moving, could some one explain to me why,
Thank You.
heres the code:

MemoryStream stream = new MemoryStream();

int patchcounter = 0;
int imagecounter = 0;

OriginalHiResPatches = new Byte[f.numImages()][][];
OriginalHiReshash1 = new byte[f.numImages()][][];

for (int i = 0; i < f.numImages(); i++)

OriginalHiResPatches[imagecounter] = new Byte[patchcounter+1][];

for (int y = 0; y < TrainingSet.images[imagecounter].Height; y ++)
for (int x = 0; x < TrainingSet.images[imagecounter].Width; x ++)

Bitmap b = new Bitmap(3, 3);
Graphics g = Graphics.FromImage(b);

g.DrawImage(TrainingSet.images[imagecounter], new Rectangle(x, y, b.Width, b.Height), new Rectangle(x, y, 3, 3), GraphicsUnit.Pixel);

b.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);

OriginalHiResPatches[imagecounter][patchcounter]=stream.ToArray() ;


Array.Resize(ref OriginalHiReshash1[imagecounter],OriginalHiReshash1[imagecounter].Length+1);

Array.Resize(ref OriginalHiResPatches[imagecounter],OriginalHiResPatches[imagecounter].Length+1);


patchcounter = 0;

Sep 18 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.