I want to open an image file (simple via Image Load) and use ImageInterploate to explore the effect of Voronoi tessellations. I need to make the image wave into a triplet wave, but I can't find out how to do this. I presume I then need to convert the tessellated wave back into an image. Is this a sensible thing to try and if so, how should I go about it? DN
I couldn't find a straightforward way to convert an image wave to a triplet wave, but it's not difficult to use some "for" loops for this purpose. Presumably there's some clever MatrixOP or ImageTransform operation that can do it more efficiently. Here's some code that converts the image to a triplet wave then back and plots it; somewhere along the way I lost a pixel, but it's close. Add your tessellation code in the middle.
function imagetoxyz(imgwave) //operates on a 2d source wave, for example grayscale wave imgwave
//first convert the image to a triplet wave using "for" loops make/O/N=(numpnts(imgwave),3) xyzwave variablei=0,j=0,k=0 for(i=0;i<dimsize(imgwave,0);i+=1) for(j=0;j<dimsize(imgwave,1);j+=1)
xyzwave[k][0]=i
xyzwave[k][1]=j
xyzwave[k][2]=imgwave[i][j][k]
k+=1 endfor endfor
/// //Do your voroni tesselation processing here on the triplet wave "xyzwave" ///
//convert back to a standard image, then plot: Make/O/N=(xyzwave[DimSize(xyzwave,0)-1][0],xyzwave[DimSize(xyzwave,0)-1][1]) newimgwave duplicate/O newimgwave countMat ImageFromXYZ xyzwave, newimgwave, countMat NewImage newimgwave end
I couldn't find a straightforward way to convert an image wave to a triplet wave, but it's not difficult to use some "for" loops for this purpose. Presumably there's some clever MatrixOP or ImageTransform operation that can do it more efficiently.
Your code is indeed straightforward. I can't think of an obvious way of using MatrixOP here (there are *only* about 170 MatrixOP functions)...
Here is another variation that does not use explicit loops:
// convert 1-layer image into a triplet wave Function imageToXYZ(inWave) Wave inWave
I would like to point out to the OP that they have to be careful in trying to use the Voronoi interpolation on data sampled on a rectangular grid. The problem is that the first step of the interpolation is the triangulation of the sampled data which is assumed to be sampled at random XY positions. As is obvious, the triangulation of samples on a rectangular grid is non-unique. This presents difficulties in the triangulation stage. IGOR attempts to introduce some perturbation to the XY locations in order to break the degeneracies.
Another consideration is that the triangulation step is performed in O(N^2) steps which is rarely justified when your data are already on a rectangular grid. So the bottom line is that you would have to have a very compelling reason to take this approach in the first place.
//operates on a 2d source wave, for example grayscale
wave imgwave
//first convert the image to a triplet wave using "for" loops
make/O/N=(numpnts(imgwave),3) xyzwave
variable i=0,j=0,k=0
for(i=0;i<dimsize(imgwave,0);i+=1)
for(j=0;j<dimsize(imgwave,1);j+=1)
xyzwave[k][0]=i
xyzwave[k][1]=j
xyzwave[k][2]=imgwave[i][j][k]
k+=1
endfor
endfor
///
//Do your voroni tesselation processing here on the triplet wave "xyzwave"
///
//convert back to a standard image, then plot:
Make/O/N=(xyzwave[DimSize(xyzwave,0)-1][0],xyzwave[DimSize(xyzwave,0)-1][1]) newimgwave
duplicate/O newimgwave countMat
ImageFromXYZ xyzwave, newimgwave, countMat
NewImage newimgwave
end
June 22, 2016 at 09:19 am - Permalink
Your code is indeed straightforward. I can't think of an obvious way of using MatrixOP here (there are *only* about 170 MatrixOP functions)...
Here is another variation that does not use explicit loops:
Function imageToXYZ(inWave)
Wave inWave
Variable rows=DimSize(inWave,0)
Variable cols=DimSize(inWave,1)
Variable nRows=rows*cols
Make/O/N=(nRows,3) tripletWave
tripletWave[][0]=mod(p,rows)
tripletWave[][1]=trunc(p/rows)
Duplicate/free inWave,ddd
Redimension/N=(nRows) ddd
tripletWave[][2]=ddd[p]
End
I would like to point out to the OP that they have to be careful in trying to use the Voronoi interpolation on data sampled on a rectangular grid. The problem is that the first step of the interpolation is the triangulation of the sampled data which is assumed to be sampled at random XY positions. As is obvious, the triangulation of samples on a rectangular grid is non-unique. This presents difficulties in the triangulation stage. IGOR attempts to introduce some perturbation to the XY locations in order to break the degeneracies.
Another consideration is that the triangulation step is performed in O(N^2) steps which is rarely justified when your data are already on a rectangular grid. So the bottom line is that you would have to have a very compelling reason to take this approach in the first place.
A.G.
WaveMetrics, Inc.
June 22, 2016 at 10:03 am - Permalink
June 22, 2016 at 06:07 pm - Permalink