Ask Your Question

Revision history [back]

how do I copy specific pixels to destination mat from source mat in opencv c++?

I want to copy specific pixels to destination mat when certain condition becomes true.in addition to that I a switching to next rows upon specific count of pixels that met condition. But it throws memory related exception as follows: * Error in `/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so': malloc(): memory corruption (fast): 0x0000000001593710 ** ======= Backtrace: ========= /lib64/libc.so.6(+0x7ab54)[0x7ffff5521b54] /lib64/libc.so.6(+0x7ddf7)[0x7ffff5524df7] /lib64/libc.so.6(__libc_malloc+0x4c)[0x7ffff552710c] /lib64/libstdc++.so.6(_Znwm+0x1d)[0x7ffff5de11bd] /usr/local/lib/libopencv_highgui.so.3.3(cvNamedWindow+0xda)[0x7ffff649eeca] /usr/local/lib/libopencv_highgui.so.3.3(_ZN2cv11namedWindowERKNS_6StringEi+0x38)[0x7ffff64957b8] /home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x409af7] /home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x408d16] /home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x405c7e] /lib64/libc.so.6(__libc_start_main+0xf5)[0x7ffff54c8c05] /home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x401f29]

platform :centos7 +opencv 3.3

how do I copy specific pixels to destination mat from source mat in opencv c++?

I want to copy specific pixels to destination mat when certain condition becomes true.in addition to that I a switching to next rows upon specific count of pixels that met condition. But it throws memory related exception as follows: * Error in `/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so': malloc(): memory corruption (fast): 0x0000000001593710 ** ======= Backtrace: ========= /lib64/libc.so.6(+0x7ab54)[0x7ffff5521b54] /lib64/libc.so.6(+0x7ddf7)[0x7ffff5524df7] /lib64/libc.so.6(__libc_malloc+0x4c)[0x7ffff552710c] /lib64/libstdc++.so.6(_Znwm+0x1d)[0x7ffff5de11bd] /usr/local/lib/libopencv_highgui.so.3.3(cvNamedWindow+0xda)[0x7ffff649eeca] /usr/local/lib/libopencv_highgui.so.3.3(_ZN2cv11namedWindowERKNS_6StringEi+0x38)[0x7ffff64957b8] /home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x409af7] /home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x408d16] /home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x405c7e] /lib64/libc.so.6(__libc_start_main+0xf5)[0x7ffff54c8c05] /home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x401f29]

platform :centos7 +opencv 3.3

code: unsigned char input = (unsigned char)(mask.data); //mask unsigned char imginput = (unsigned char)(img.data); // source data int m=0,n=0; for(i=hinfo[1];i<hinfo[1]+hinfo[3];i++) <br=""> { if(hfcnt>=htotalpix) // max no of pixels break;
int cnt=0; for(j=hinfo[0];j<hinfo[0]+hinfo[2];j++) {="" valmask="input[mask.cols" *i="" +j="" ]="" ;="" if(valmask="=255)" *condition*="" {="" patch1.at<vec3b="">(m,n)[0]=imginput[jimg.cols1 + i1 + 0]; patch1.at<vec3b>(m,n)[0]=imginput[jimg.cols2 + i2 + 0]; patch1.at<vec3b>(m,n)[0]=imginput[jimg.cols2 + i3 + 0]; hfcnt++; cnt++; } else continue; / to switch to next row in source*/ if(cnt==hinfo[2]) break; n++; } m++; }

click to hide/show revision 3
None

updated 2017-11-23 01:57:33 -0600

berak gravatar image

how do I copy specific pixels to destination mat from source mat in opencv c++?

I want to copy specific pixels to destination mat when certain condition becomes true.in addition to that I a switching to next rows upon specific count of pixels that met condition. But it throws memory related exception as follows: * follows:

** Error in `/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so': malloc(): memory corruption (fast): 0x0000000001593710 **
***
======= Backtrace: =========
/lib64/libc.so.6(+0x7ab54)[0x7ffff5521b54]
/lib64/libc.so.6(+0x7ddf7)[0x7ffff5524df7]
/lib64/libc.so.6(__libc_malloc+0x4c)[0x7ffff552710c]
/lib64/libstdc++.so.6(_Znwm+0x1d)[0x7ffff5de11bd]
/usr/local/lib/libopencv_highgui.so.3.3(cvNamedWindow+0xda)[0x7ffff649eeca]
/usr/local/lib/libopencv_highgui.so.3.3(_ZN2cv11namedWindowERKNS_6StringEi+0x38)[0x7ffff64957b8]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x409af7]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x408d16]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x405c7e]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7ffff54c8c05]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x401f29]

/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x401f29] platform :centos7 +opencv 3.33.3

code:

code:

unsigned char input *input = (unsigned char)(mask.data); char*)(mask.data);  //mask
 unsigned char imginput *imginput = (unsigned char)(img.data); char*)(img.data); // source data
 int m=0,n=0;
 for(i=hinfo[1];i<hinfo[1]+hinfo[3];i++) <br="">
 {
 if(hfcnt>=htotalpix) // max no of pixels
 break; 
int cnt=0; for(j=hinfo[0];j<hinfo[0]+hinfo[2];j++) {="" valmask="input[mask.cols" *i="" +j="" ]="" ;="" if(valmask="=255)" *condition*="" {="" patch1.at<vec3b="">(m,n)[0]=imginput[jimg.cols1 + i1 for(j=hinfo[0];j<hinfo[0]+hinfo[2];j++) { valmask=input[mask.cols *i +j ] ; if(valmask==255) /*condition*/ { patch1.at<Vec3b>(m,n)[0]=imginput[j*img.cols*1 + i*1 + 0]; patch1.at<vec3b>(m,n)[0]=imginput[jimg.cols2 + i2 patch1.at<Vec3b>(m,n)[0]=imginput[j*img.cols*2 + i*2 + 0]; patch1.at<vec3b>(m,n)[0]=imginput[jimg.cols2 + i3 patch1.at<Vec3b>(m,n)[0]=imginput[j*img.cols*2 + i*3 + 0]; hfcnt++; cnt++; } else continue; / /* to switch to next row in source*/ if(cnt==hinfo[2]) break; n++; } m++; }

}

how do I copy specific pixels to destination mat from source mat in opencv c++?

I want to copy specific pixels to destination mat when certain condition becomes true.in addition to that I a switching to next rows upon specific count of pixels that met condition. But it throws memory related exception as follows:

** follows:
* Error in `/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so': malloc(): memory corruption (fast): 0x0000000001593710 ***
**
======= Backtrace: =========
/lib64/libc.so.6(+0x7ab54)[0x7ffff5521b54]
/lib64/libc.so.6(+0x7ddf7)[0x7ffff5524df7]
/lib64/libc.so.6(__libc_malloc+0x4c)[0x7ffff552710c]
/lib64/libstdc++.so.6(_Znwm+0x1d)[0x7ffff5de11bd]
/usr/local/lib/libopencv_highgui.so.3.3(cvNamedWindow+0xda)[0x7ffff649eeca]
/usr/local/lib/libopencv_highgui.so.3.3(_ZN2cv11namedWindowERKNS_6StringEi+0x38)[0x7ffff64957b8]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x409af7]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x408d16]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x405c7e]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7ffff54c8c05]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x401f29]

/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x401f29]

platform :centos7 +opencv 3.3

3.3

code:

code:
    unsigned char *input input = (unsigned char*)(mask.data); char)(mask.data);  //mask
 unsigned char *imginput imginput = (unsigned char*)(img.data); char)(img.data); // source data
 int m=0,n=0;
 for(i=hinfo[1];i<hinfo[1]+hinfo[3];i++)  <br="">
    {
 if(hfcnt>=htotalpix)  // max no of pixels 
 break;  
int cnt=0; for(j=hinfo[0];j<hinfo[0]+hinfo[2];j++) { valmask=input[mask.cols *i +j ] ; if(valmask==255) /*condition*/ { patch1.at<Vec3b>(m,n)[0]=imginput[j*img.cols*1 + i*1 for(j=hinfo[0];j<hinfo[0]+hinfo[2];j++) {="" valmask="input[mask.cols" *i="" +j="" ]="" ;="" if(valmask="=255)" *condition*="" {="" patch1.at<vec3b="">(m,n)[0]=imginput[jimg.cols1 + i1 + 0]; patch1.at<Vec3b>(m,n)[0]=imginput[j*img.cols*2 + i*2 patch1.at<vec3b>(m,n)[0]=imginput[jimg.cols2 + i2 + 0]; patch1.at<Vec3b>(m,n)[0]=imginput[j*img.cols*2 + i*3 patch1.at<vec3b>(m,n)[0]=imginput[jimg.cols2 + i3 + 0]; hfcnt++; cnt++; } else continue; /* / to switch to next row in source*/ if(cnt==hinfo[2]) break; n++; } m++; }
}

how do I copy specific pixels to destination mat from source mat in opencv c++?

I want to copy specific pixels to destination mat when certain condition becomes true.in addition to that I a switching to next rows upon specific count of pixels that met condition. But it throws memory related exception as follows: * Error in `/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so': malloc(): memory corruption (fast): 0x0000000001593710 ** ======= Backtrace: ========= /lib64/libc.so.6(+0x7ab54)[0x7ffff5521b54] /lib64/libc.so.6(+0x7ddf7)[0x7ffff5524df7] /lib64/libc.so.6(__libc_malloc+0x4c)[0x7ffff552710c] /lib64/libstdc++.so.6(_Znwm+0x1d)[0x7ffff5de11bd] /usr/local/lib/libopencv_highgui.so.3.3(cvNamedWindow+0xda)[0x7ffff649eeca] /usr/local/lib/libopencv_highgui.so.3.3(_ZN2cv11namedWindowERKNS_6StringEi+0x38)[0x7ffff64957b8] /home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x409af7] /home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x408d16] /home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x405c7e] /lib64/libc.so.6(__libc_start_main+0xf5)[0x7ffff54c8c05] /home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x401f29]

platform :centos7 +opencv 3.3

code: unsigned char input = (unsigned char)(mask.data); //mask unsigned char imginput = (unsigned char)(img.data); // source data int m=0,n=0; for(i=hinfo[1];i<hinfo[1]+hinfo[3];i++) <br=""> { if(hfcnt>=htotalpix) // max no of pixels break;
int cnt=0; for(j=hinfo[0];j<hinfo[0]+hinfo[2];j++) {="" valmask="input[mask.cols" *i="" +j="" ]="" ;="" if(valmask="=255)" *condition*="" {="" patch1.at<vec3b="">(m,n)[0]=imginput[jimg.cols1 + i1 + 0]; patch1.at<vec3b>(m,n)[0]=imginput[jimg.cols2 + i2 + 0]; patch1.at<vec3b>(m,n)[0]=imginput[jimg.cols2 + i3 + 0]; hfcnt++; cnt++; } else continue; / to switch to next row in source*/ if(cnt==hinfo[2]) break; n++; } m++; }

click to hide/show revision 6
None

updated 2017-11-23 02:05:41 -0600

berak gravatar image

how do I copy specific pixels to destination mat from source mat in opencv c++?

I want to copy specific pixels to destination mat when certain condition becomes true.in addition to that I a switching to next rows upon specific count of pixels that met condition. But it throws memory related exception as follows: * follows:

** Error in `/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so': malloc(): memory corruption (fast): 0x0000000001593710 **
***
======= Backtrace: =========
/lib64/libc.so.6(+0x7ab54)[0x7ffff5521b54]
/lib64/libc.so.6(+0x7ddf7)[0x7ffff5524df7]
/lib64/libc.so.6(__libc_malloc+0x4c)[0x7ffff552710c]
/lib64/libstdc++.so.6(_Znwm+0x1d)[0x7ffff5de11bd]
/usr/local/lib/libopencv_highgui.so.3.3(cvNamedWindow+0xda)[0x7ffff649eeca]
/usr/local/lib/libopencv_highgui.so.3.3(_ZN2cv11namedWindowERKNS_6StringEi+0x38)[0x7ffff64957b8]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x409af7]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x408d16]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x405c7e]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7ffff54c8c05]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x401f29]

/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x401f29]

platform :centos7 +opencv 3.3

code: code:

unsigned char input *input = (unsigned char)(mask.data); char*)(mask.data);  //mask
 unsigned char imginput *imginput = (unsigned char)(img.data); char*)(img.data); // source data
 int m=0,n=0;
 for(i=hinfo[1];i<hinfo[1]+hinfo[3];i++) <br="">
     {
 if(hfcnt>=htotalpix)  // max no of pixels 
 break; 
int cnt=0; for(j=hinfo[0];j<hinfo[0]+hinfo[2];j++) {="" valmask="input[mask.cols" *i="" +j="" ]="" ;="" if(valmask="=255)" *condition*="" {="" patch1.at<vec3b="">(m,n)[0]=imginput[jimg.cols1 + i1 for(j=hinfo[0];j<hinfo[0]+hinfo[2];j++) { valmask=input[mask.cols *i +j ] ; if(valmask==255) /*condition*/ { patch1.at<Vec3b>(m,n)[0]=imginput[j*img.cols*1 + i*1 + 0]; patch1.at<vec3b>(m,n)[0]=imginput[jimg.cols2 + i2 patch1.at<Vec3b>(m,n)[0]=imginput[j*img.cols*2 + i*2 + 0]; patch1.at<vec3b>(m,n)[0]=imginput[jimg.cols2 + i3 patch1.at<Vec3b>(m,n)[0]=imginput[j*img.cols*2 + i*3 + 0]; hfcnt++; cnt++; } else continue; / /* to switch to next row in source*/ if(cnt==hinfo[2]) break; n++; } m++; }

}

how do I copy specific pixels to destination mat from source mat in opencv c++?

I want to copy specific pixels to destination mat when certain condition becomes true.in addition to that I a switching to next rows upon specific count of pixels that met condition. But it throws memory related exception as follows:

** Error in `/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so': malloc(): memory corruption (fast): 0x0000000001593710 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x7ab54)[0x7ffff5521b54]
/lib64/libc.so.6(+0x7ddf7)[0x7ffff5524df7]
/lib64/libc.so.6(__libc_malloc+0x4c)[0x7ffff552710c]
/lib64/libstdc++.so.6(_Znwm+0x1d)[0x7ffff5de11bd]
/usr/local/lib/libopencv_highgui.so.3.3(cvNamedWindow+0xda)[0x7ffff649eeca]
/usr/local/lib/libopencv_highgui.so.3.3(_ZN2cv11namedWindowERKNS_6StringEi+0x38)[0x7ffff64957b8]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x409af7]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x408d16]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x405c7e]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7ffff54c8c05]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x401f29]

platform :centos7 +opencv 3.3

code:

unsigned char *input = (unsigned char*)(mask.data);  //mask
unsigned char *imginput = (unsigned char*)(img.data); // source data
int m=0,n=0;
for(i=hinfo[1];i<hinfo[1]+hinfo[3];i++)                 
{
if(hfcnt>=htotalpix)  // max no of pixels 
break;       
int cnt=0;
for(j=hinfo[0];j<hinfo[0]+hinfo[2];j++)
{
valmask=input[mask.cols *i  +j ] ;
if(valmask==255)  /*condition*/
{
patch1.at<Vec3b>(m,n)[0]=imginput[j*img.cols*1 + i*1 + 0];
patch1.at<Vec3b>(m,n)[0]=imginput[j*img.cols*2 + i*2 + 0];
patch1.at<Vec3b>(m,n)[0]=imginput[j*img.cols*2 + i*3 + 0];
hfcnt++;
cnt++;
}
else
continue;
/* to switch to next row in source*/
if(cnt==hinfo[2])
break; 
n++;
}
m++;
}

here are the images extracted using copyTo , in these images there is a area having black pixels which I don't want to copy. That's why I am copying specific pixels.

image description image description

how do I copy specific pixels to destination mat from source mat in opencv c++?

I want to copy specific pixels to destination mat when certain condition becomes true.in addition to that I a switching to next rows upon specific count of pixels that met condition. But it throws memory related exception as follows:

** Error in `/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so': malloc(): memory corruption (fast): 0x0000000001593710 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x7ab54)[0x7ffff5521b54]
/lib64/libc.so.6(+0x7ddf7)[0x7ffff5524df7]
/lib64/libc.so.6(__libc_malloc+0x4c)[0x7ffff552710c]
/lib64/libstdc++.so.6(_Znwm+0x1d)[0x7ffff5de11bd]
/usr/local/lib/libopencv_highgui.so.3.3(cvNamedWindow+0xda)[0x7ffff649eeca]
/usr/local/lib/libopencv_highgui.so.3.3(_ZN2cv11namedWindowERKNS_6StringEi+0x38)[0x7ffff64957b8]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x409af7]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x408d16]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x405c7e]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7ffff54c8c05]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x401f29]

platform :centos7 +opencv 3.3

code:

unsigned char *input = (unsigned char*)(mask.data);  //mask
unsigned char *imginput = (unsigned char*)(img.data); // source data
int m=0,n=0;
for(i=hinfo[1];i<hinfo[1]+hinfo[3];i++)                 
{
if(hfcnt>=htotalpix)  // max no of pixels 
break;       
int cnt=0;
for(j=hinfo[0];j<hinfo[0]+hinfo[2];j++)
{
valmask=input[mask.cols *i  +j ] ;
if(valmask==255)  /*condition*/
{
patch1.at<Vec3b>(m,n)[0]=imginput[j*img.cols*1 + i*1 + 0];
patch1.at<Vec3b>(m,n)[0]=imginput[j*img.cols*2 patch1.at<Vec3b>(m,n)[1]=imginput[j*img.cols*2 + i*2 + 0];
patch1.at<Vec3b>(m,n)[0]=imginput[j*img.cols*2 patch1.at<Vec3b>(m,n)[2]=imginput[j*img.cols*2 + i*3 + 0];
hfcnt++;
cnt++;
}
else
continue;
/* to switch to next row in source*/
if(cnt==hinfo[2])
break; 
n++;
}
m++;
}

here are the images extracted using copyTo , in these images there is a area having black pixels which I don't want to copy. That's why I am copying specific pixels.

image description image description

how do I copy specific pixels to destination mat from source mat in opencv c++?

I want to copy specific pixels to destination mat when certain condition becomes true.in addition to that I a switching to next rows upon specific count of pixels that met condition. But it throws memory related exception as follows:

** Error in `/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so': malloc(): memory corruption (fast): 0x0000000001593710 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x7ab54)[0x7ffff5521b54]
/lib64/libc.so.6(+0x7ddf7)[0x7ffff5524df7]
/lib64/libc.so.6(__libc_malloc+0x4c)[0x7ffff552710c]
/lib64/libstdc++.so.6(_Znwm+0x1d)[0x7ffff5de11bd]
/usr/local/lib/libopencv_highgui.so.3.3(cvNamedWindow+0xda)[0x7ffff649eeca]
/usr/local/lib/libopencv_highgui.so.3.3(_ZN2cv11namedWindowERKNS_6StringEi+0x38)[0x7ffff64957b8]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x409af7]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x408d16]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x405c7e]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7ffff54c8c05]
/home/ds/eclipse-workspace/pixelenc_current/Debug/pixelenc_current.so[0x401f29]

platform :centos7 +opencv 3.3

code:

unsigned char *input = (unsigned char*)(mask.data);  //mask
unsigned char *imginput = (unsigned char*)(img.data); // source data
int m=0,n=0;
for(i=hinfo[1];i<hinfo[1]+hinfo[3];i++)                 
{
if(hfcnt>=htotalpix)  // max no of pixels 
break;       
int cnt=0;
for(j=hinfo[0];j<hinfo[0]+hinfo[2];j++)
{
valmask=input[mask.cols *i  +j ] ;
if(valmask==255)  /*condition*/
{
patch1.at<Vec3b>(m,n)[0]=imginput[j*img.cols*1 + i*1 + 0];
patch1.at<Vec3b>(m,n)[1]=imginput[j*img.cols*2 + i*2 + 0];
patch1.at<Vec3b>(m,n)[2]=imginput[j*img.cols*2 + i*3 + 0];
hfcnt++;
cnt++;
}
else
continue;
/* to switch to next row in source*/
if(cnt==hinfo[2])
break; 
n++;
}
m++;
}

here are the images extracted using copyTo , in these images there is a area having black pixels which I don't want to copy. That's why I am copying specific pixels.

image description image description

Here is one of the mask I used to extract sub images. Its different one, right now I cannot produce the mask used to extract above images. image description