Permalink
Browse files

Image from tiles

Fixed image order of Image.montage to be 
compatible with Sampling.getTiles. Also, added
helpful function to keep the coordinates with
extracted tiles, so the original image can be 
safely reconstructed.
  • Loading branch information...
1 parent 40ff375 commit fc325c0f093a5fb11eb9783a060a606454751f10 Ville Tirronen committed Jan 26, 2011
Showing with 37 additions and 9 deletions.
  1. +15 −6 CV/Image.chs
  2. +6 −3 CV/Sampling.hs
  3. BIN examples/smallLena.jpg
  4. +16 −0 examples/splitMerge.hs
View
@@ -138,11 +138,6 @@ tileImages image1 image2 (x,y) = unsafePerformIO $
creatingImage ({#call simpleMergeImages#}
i1 i2 x y)
-- | Blit image2 onto image1.
---blit image1 image2 (x,y) =
--- withImage image1 $ \i1 ->
--- withImage image2 $ \i2 ->
--- ({#call plainBlit#} i1 i2 x y)
--- TODO: Remove the above
blitFix = blit
blit image1 image2 (x,y)
| badSizes = error $ "Bad blit sizes: " ++ show [(w1,h1),(w2,h2)]++"<-"++show (x,y)
@@ -152,6 +147,18 @@ blit image1 image2 (x,y)
where
((w1,h1),(w2,h2)) = (getSize image1,getSize image2)
badSizes = x+w2>w1 || y+h2>h1 || x<0 || y<0
+
+-- | blit multiple tiles into one image
+blitM :: (Int,Int) -> [((Int,Int),Image)] -> Image
+blitM (rw,rh) imgs = resultPic
+ where
+ resultPic = unsafePerformIO $ do
+ r <- createImage32F (fromIntegral rw,fromIntegral rh) 1
+ sequence_ [blit r i (fromIntegral x, fromIntegral y)
+ | ((x,y),i) <- imgs ]
+ return r
+
+
subPixelBlit
:: Image -> Image -> (CDouble, CDouble) -> IO ()
@@ -268,6 +275,8 @@ montage (u',v') space' imgs = resultPic
edge = space`div`2
resultPic = unsafePerformIO $ do
r <- createImage32F (rw,rh) 1
- sequence_ [blit r i (edge + x*xstep, edge + y*ystep) | y <- [0..v-1] , x <- [0..u-1] | i <- imgs ]
+ sequence_ [blit r i (edge + x*xstep, edge + y*ystep)
+ | x <- [0..u-1], y <- [0..v-1]
+ | i <- imgs ]
return r
View
@@ -21,6 +21,7 @@ allPatches size image = [getRegion (x,y) size image
allButLast = reverse.tail.reverse
-- Get all non-overlapping patches of image
getTiles size image = getOverlappedTiles size (0,0) image
+getTilesC size image = getOverlappedTilesC size (0,0) image
-- Get Coordinates for overlapping tiles
getOverlappedTileCoords size (xover,yover) image
@@ -34,11 +35,13 @@ getOverlappedTileCoords size (xover,yover) image
,floor $ fromIntegral h*(1-yover))
-- Get overlapping tiles
-getOverlappedTiles :: (CInt,CInt) -> (CDouble,CDouble) -> Image -> [Image]
-getOverlappedTiles size overlap image
- = map (\c -> getRegion c size image)
+getOverlappedTiles s o i = map snd $ getOverlappedTilesC s o i
+getOverlappedTilesC :: (Int,Int) -> (CDouble,CDouble) -> Image -> [((Int,Int),Image)]
+getOverlappedTilesC size overlap image
+ = map (\c -> (both fromIntegral c,getRegion c size image))
$ getOverlappedTileCoords size
overlap image
+both f (a,b) = (f a, f b)
getMarkedAndUnmarkedTiles size overlap image marks =
(map fst markedTiles,map fst nonMarked)
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,16 @@
+module Main where
+import CV.Image
+import CV.Sampling
+
+-- | Output:
+-- splitLena.jpg - Lena image split to tiles with few pixels of black between tiles
+-- splitLena2.jpg - Lena image split to tiles and joined safely back to original
+main = do
+ Just x <- loadImage "smallLena.jpg"
+ let pieces = getTiles (30,30) x
+ piecesWithCoordinates = getTilesC (30,30) x
+ joined = montage (6,6) 5 pieces
+ blitted = blitM (205,205) piecesWithCoordinates
+ saveImage "splitLena.jpg" joined
+ saveImage "splitLena2.jpg" blitted
+

0 comments on commit fc325c0

Please sign in to comment.