Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/micmacIGN/micmac
Browse files Browse the repository at this point in the history
  • Loading branch information
deseilligny committed May 18, 2021
2 parents 8da3b3c + 8733faa commit 7378653
Show file tree
Hide file tree
Showing 4 changed files with 3,211 additions and 3 deletions.
17 changes: 16 additions & 1 deletion MMVII/apipy/ex/ex1.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,26 @@ def imageScale():
def imgNumpyRawData():
im=mmv2.cIm2Du1.FromFile("ex/image.tif")
d=im.DIm()
v=d.rawData()
v=d.getRawData()
from PIL import Image
import numpy as np
array = np.array(v, dtype=np.uint8)
array = array.reshape((d.SzY(), d.SzX()))
img = Image.fromarray(array)
img.show()

def PIL2mmv2Img():
from PIL import Image
import numpy as np
path="ex/png.png"
pil_image = Image.open(path).convert('L')
pil_image_array=np.array(pil_image)
im=mmv2.cIm2Du1( (5,5) )
im.DIm().setRawData( pil_image_array )
d=im.DIm()
v=d.getRawData()
array = np.array(v, dtype=np.uint8)
array = array.reshape((d.SzY(), d.SzX()))
img = Image.fromarray(array)
img.show()

2 changes: 1 addition & 1 deletion MMVII/apipy/gen_typemaps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

dimNames = ['x', 'y', 'z']
debug = False
Expand Down
15 changes: 14 additions & 1 deletion MMVII/apipy/mmv2.i
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
%}

//----------------------------------------------------------------------
%include "numpy.i"
%init %{
import_array();
%}

#define ElSTDNS std::
#define ElTmplSpecNull template <>
%include <std_string.i>
Expand Down Expand Up @@ -225,14 +230,22 @@ mmv2_init();
}
}


//must redefine virtual functions to access base class methods,
//when base class is abstract and template?
%extend MMVII::cDataIm2D<tU_INT1> {
std::vector<tU_INT1> rawData() {
std::vector<tU_INT1> getRawData() {
int size = $self->SzX()*$self->SzY();
tU_INT1* data = $self->RawDataLin();
std::vector<tU_INT1> out(data ,data + size);
return out;
}
//here tU_INT1* IN_ARRAY2 is not recognized
void setRawData(unsigned char* IN_ARRAY2, int DIM1, int DIM2) {
$self->Resize( MMVII::cPtxd<int,2>(0,0), MMVII::cPtxd<int,2>(DIM2,DIM1) );
for (long i=0;i<DIM1*DIM2;i++)
$self->RawDataLin()[i] = IN_ARRAY2[i];
}
}


Loading

0 comments on commit 7378653

Please sign in to comment.