You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have some problems with using masked images. I try to create a masked image from a normal one by using a fromFunction and although the function itself compiles correctly, the application of the function yields a type error during compilation. I set up an equivalent example to illustrate the problem as my original function is a bit complex.
{-# LANGUAGE ScopedTypeVariables, TypeFamilies #-}
import Vision.Image
import Vision.Image.Storage.DevIL (Autodetect (..), load)
import Vision.Primitive
maskImage :: (Image i1, FromFunction i,
FromFunctionPixel i ~ Maybe (ImagePixel i1))
=> i1 -> i
maskImage img = fromFunction (shape img) maskPixel
where maskPixel p = Just $ img `index` p
main = do
io <- load Autodetect "../test.jpg"
case io of
Right (rgb :: RGB) -> do
let i' = maskImage rgb
print "Processed image"
The snippet yields the compilation error:
Main.hs:27:22:
Couldn't match type ‘FromFunctionPixel i0’ with ‘Maybe RGBPixel’
The type variable ‘i0’ is ambiguous
Expected type: Maybe (ImagePixel RGB)
Actual type: FromFunctionPixel i0
Relevant bindings include i' :: i0 (bound at Main.hs:27:17)
In the expression: maskImage rgb
In an equation for ‘i'’: i' = maskImage rgb
In the expression:
do { let i' = maskImage rgb;
print "Processed image" }
I also tried to create to unmask the image afterwards but this didn't work either. So how would one create a masked image with fromFunction and destruct it later again? Or why doesn't my code compile correctly?
Background: I try to implement an image registration algorithm. One step of the algorithm is to interpolate the moved image at the points of the orgiinal image. As usually not all pixels of the original and the moved image overlap, a masked image was my data structure of choice to represent the result of this processing step.
The text was updated successfully, but these errors were encountered:
herrzinter
changed the title
Constructing (and destructing) masked images
How can I construct (and destruct) masked images?
Apr 20, 2016
The code compiles, if the type signature :: DelayedMask RGBPixel is added to the i' variable:
let i' = maskImage rgb :: DelayedMask RGBPixel
The problem arised as the fromFunction, and thus, the maskImage function are polymorphic ie. there type signature uses a type variable. At compile time, the compiler has to known the concrete type of this variable, thus, the type has to be specified explicitely or the compiler has to be able to infer the value. The type signature defines the type explicetly ie. it tells the compiler, that the application of the maskImage function results in a masked image of rgb pixels. Similiarly, if the convert function is used, the types have be instances of the corresponding typeclass, and the output type has to be specified by a type signature if it cannot be infered otherwise.
I have some problems with using masked images. I try to create a masked image from a normal one by using a
fromFunction
and although the function itself compiles correctly, the application of the function yields a type error during compilation. I set up an equivalent example to illustrate the problem as my original function is a bit complex.The snippet yields the compilation error:
I also tried to create to unmask the image afterwards but this didn't work either. So how would one create a masked image with
fromFunction
and destruct it later again? Or why doesn't my code compile correctly?Background: I try to implement an image registration algorithm. One step of the algorithm is to interpolate the moved image at the points of the orgiinal image. As usually not all pixels of the original and the moved image overlap, a masked image was my data structure of choice to represent the result of this processing step.
The text was updated successfully, but these errors were encountered: