수백만 개의 픽셀이있는 2D 박스없는 픽셀 배열에는 어떤 Haskell 표현이 권장됩니까?
Haskell의 일부 이미지 처리 문제를 해결하고 싶습니다. 나는 bitonal (bitmap) 및 수백만 개의 픽셀이있는 컬러 이미지로 작업하고 있습니다. 여러 가지 질문이 있습니다.
어떤 기준에 나는 사이에서 선택해야
Vector.Unboxed하고UArray? 둘 다 박스형 배열이지만Vector추상화는 특히 루프 융합과 관련 하여 많이 보급 된 것으로 보입니다. 가Vector항상 좋은 것은? 그렇지 않다면 언제 어떤 표현을 사용해야합니까?컬러 이미지의 경우 16 비트 정수의 3 배 또는 단 정밀도 부동 소수점 숫자의 3 배를 저장하려고합니다. 이를 위해 중 하나입니다
Vector또는UArray사용에 쉽게? 더 공연?흑백 이미지의 경우 픽셀 당 1 비트 만 저장하면됩니다. 여러 픽셀을 단어로 묶어 여기에 도움이 될 수있는 미리 정의 된 데이터 유형이 있습니까?
마지막으로 내 배열은 2 차원입니다. "배열의 배열"(또는 벡터의 벡터)로 표현하여 부과되는 추가 간접 처리를 처리 할 수 있지만 인덱스 매핑 지원을 갖는 추상화를 선호합니다. 누구든지 표준 라이브러리 또는 Hackage에서 추천 할 수 있습니까?
나는 기능 프로그래머이며 돌연변이가 필요하지 않습니다 :-)
다차원 배열의 경우 내 생각에 Haskell의 현재 최상의 옵션은 repa 입니다.
Repa는 고성능의 규칙적인 다차원 형상 다형성 병렬 어레이를 제공합니다. 모든 숫자 데이터는 박스 형태로 저장됩니다. 프로그램을 실행할 때 명령 행에서 + RTS -N을 제공하면 Repa 결합기로 작성된 기능이 자동으로 병렬됩니다.
최근에는 일부 이미지 처리 문제에 사용되었습니다.
하스켈 배열이나 벡터 라이브러리를 이미 알고 있다면 시작하기에 좋은 장소 인 repa 사용에 대한 자습서를 작성하기 시작했습니다 . 중요한 디딤돌은 다차원 지수 (및 스텐실)를 다루기 위해 단순한 인덱스 유형 대신 모양 유형을 사용하는 것입니다.
바디 수리-IO 패키지는 더 형식에 대한 지원이 필요하지만, 읽기, .BMP 이미지 파일 작성에 대한 지원이 포함되어 있습니다.
구체적인 질문을 해결하기 위해 다음은 토론이 포함 된 그래픽입니다.

Vector.Unboxed와 UArray 중에서 어떤 기준을 선택해야합니까?
그들은 약하지만, 주요 차이점은 벡터 작업을위한 API의 폭이 동일한 기본 표현이 : 그들은 당신이 (융합 기반 최적화 프레임 워크) 목록과 일반적으로 연관 좋겠 거의 모든 작업을 가지고있는 동안 UArray거의있다 API가 없습니다.
컬러 이미지의 경우 16 비트 정수의 3 배 또는 단 정밀도 부동 소수점 숫자의 3 배를 저장하려고합니다.
UArray인덱싱에 임의의 데이터 유형을 사용할 수 있으므로 다차원 데이터를 더 잘 지원합니다. 이것이 가능하지만 Vector( UA요소 유형 에 대한 인스턴스를 작성하여 ) 가능하지만 기본 목표는 아닙니다. Vector대신 Repa단계가 효율적으로 저장된 사용자 정의 데이터 유형을 매우 쉽게 사용할 수 있습니다. 모양 인덱싱 덕분 입니다.
에서 Repa트리플 반바지는 다음과 같은 유형을 갖습니다.
Array DIM3 Word16
즉, Word16의 3D 배열입니다.
흑백 이미지의 경우 픽셀 당 1 비트 만 저장하면됩니다.
UArrays는 Bools를 비트로 압축하고, Vector는 비트 패킹을 수행하는 Bool 인스턴스를 대신에 기반한 표현을 사용합니다 Word8. - Howver,이 벡터에 대한 비트 패킹 구현을 작성하기 쉬운 여기 하나입니다 (구식) uvector 라이브러리. 후드 아래에서를 Repa사용 Vectors하므로 라이브러리 표현 선택을 상속한다고 생각합니다.
여러 픽셀을 단어로 묶어 여기에 도움이되는 미리 정의 된 데이터 유형이 있습니까?
라이브러리, 단어 유형별로 기존 인스턴스를 사용할 수 있지만, Data.Bits를 사용하여 압축 된 데이터를 롤 및 언 롤링하는 데 몇 가지 도우미를 작성해야 할 수도 있습니다.
마지막으로 내 배열은 2 차원입니다
UArray와 Repa는 효율적인 다차원 배열을 지원합니다. Repa에는 또한이를위한 풍부한 인터페이스가 있습니다. 그 자체로는 벡터가 아닙니다.
주목할만한 언급 :
- hmatrix , 선형 대수 패키지에 광범위하게 바인딩 된 맞춤형 배열 유형.
vector또는repa유형 을 사용하도록 바인딩해야합니다 . - ix-shapeable , 일반 배열에서보다 유연한 색인 생성
- 칠판 , 2D 이미지 조작을위한 Andy Gill의 라이브러리
- codec-image-devil , UArray에 다양한 이미지 형식을 읽고 씁니다.
일단 나에게 중요한 Haskell 배열 라이브러리의 기능을 검토하고 비교 테이블을 컴파일 했습니다 ( 직접 스프레드 시트 : direct link ). 그래서 대답하려고 노력할 것입니다.
Vector.Unboxed와 UArray 중에서 어떤 기준을 선택해야합니까? 둘 다 박스형 배열이지만 벡터 추상화는 특히 루프 융합과 관련하여 많이 광고되는 것 같습니다. 벡터가 항상 더 낫습니까? 그렇지 않다면 언제 어떤 표현을 사용해야합니까?
2 차원 또는 다차원 배열이 필요한 경우 UArray가 Vector보다 선호 될 수 있습니다. 그러나 Vector에는 벡터 조작을위한 더 좋은 API가 있습니다. 일반적으로 Vector는 다차원 배열을 시뮬레이션하는 데 적합하지 않습니다.
Vector. Unboxed는 병렬 전략과 함께 사용할 수 없습니다. 나는 UArray를 사용할 수 없다고 생각하지만, 적어도 UArray에서 박스형 어레이로 전환하는 것이 매우 쉽고 병렬화가 복싱 비용을 초과하는 이점이 있는지 확인하십시오.
For color images I will wish to store triples of 16-bit integers or triples of single-precision floating-point numbers. For this purpose, is either Vector or UArray easier to use? More performant?
I tried using Arrays to represent images (though I needed only grayscale images). For color images I used Codec-Image-DevIL library to read/write images (bindings to DevIL library), for grayscale images I used pgm library (pure Haskell).
My major problem with Array was that it provides only random access storage, but it doesn't provide many means of building Array algorithms nor doesn't come with ready to use libraries of array routines (doesn't interface with linear algebra libs, doesn't allow to express convolutions, fft and other transforms).
Almost every time a new Array has to be built from the existing one, an intermediate list of values has to be constructed (like in matrix multiplication from the Gentle Introduction). The cost of array construction often out-weights the benefits of faster random access, to the point that a list-based representation is faster in some of my use cases.
STUArray could have helped me, but I didn't like fighting with cryptic type errors and efforts necessary to write polymorphic code with STUArray.
So the problem with Arrays is that they are not well suited for numerical computations. Hmatrix' Data.Packed.Vector and Data.Packed.Matrix are better in this respect, because they come along with a solid matrix library (attention: GPL license). Performance-wise, on matrix multiplication, hmatrix was sufficiently fast (only slightly slower than Octave), but very memory-hungry (consumed several times more than Python/SciPy).
There is also blas library for matrices, but it doesn't build on GHC7.
I didn't have much experience with Repa yet, and I don't understand repa code well. From what I see it has very limited range of ready to use matrix and array algorithms written on top of it, but at least it is possible to express important algorithms by the means of the library. For example, there are already routines for matrix multiplication and for convolution in repa-algorithms. Unfortunately, it seems that convolution is now limited to 7×7 kernels (it's not enough for me, but should suffice for many uses).
I didn't try Haskell OpenCV bindings. They should be fast, because OpenCV is really fast, but I am not sure if the bindings are complete and good enough to be usable. Also, OpenCV by its nature is very imperative, full of destructive updates. I suppose it's hard to design a nice and efficient functional interface on top of it. If one goes OpenCV way, he is likely to use OpenCV image representation everywhere, and use OpenCV routines to manipulate them.
For bitonal images I will need to store only 1 bit per pixel. Is there a predefined datatype that can help me here by packing multiple pixels into a word, or am I on my own?
As far as I know, Unboxed arrays of Bools take care of packing and unpacking bit vectors. I remember looking at implementation of arrays of Bools in other libraries, and didn't see this elsewhere.
Finally, my arrays are two-dimensional. I suppose I could deal with the extra indirection imposed by a representation as "array of arrays" (or vector of vectors), but I'd prefer an abstraction that has index-mapping support. Can anyone recommend anything from a standard library or from Hackage?
Apart from Vector (and simple lists), all other array libraries are capable of representing two-dimensional arrays or matrices. I suppose they avoid unneccesary indirection.
Although, this doesn't exactly answer your question and isn't really even haskell as such, I would recommend taking a look at CV or CV-combinators libraries at hackage. They bind the many rather useful image processing and vision operators from the opencv-library and make working with machine vision problems much faster.
It would be rather great if someone figures out how repa or some such array library could be directly used with opencv.
Here is a new Haskell Image Processing library that can handle all of the tasks in question and much more. Currently it uses Repa and Vector packages for underlying representations, which consequently inherits fusion, parallel computation, mutation and most of the other goodies that come with those libraries. It provides an easy to use interface that is natural for image manipulation:
- 2D indexing and unboxed pixels with arbitrary precision (
Double,Float,Word16, etc..) - all essential functions like
map,fold,zipWith,traverse... - support for various color spaces: RGB, HSI, gray scale, Bi-tonal, Complex, etc.
- common image processing functionality:
- Binary morphology
- Convolution
- Interpolation
- Fourier transform
- Histogram plotting
- etc.
- Ability to treat pixels and images as regular numbers.
- Reading and writing common image formats through JuicyPixels library
Most importantly, it is a pure Haskell library, so it does not depend on any external programs. It is also highly extendable, new color spaces and image representations can be introduced.
One thing that it does not do is packing multiple binary pixels in a Word, instead it uses a Word per binary pixel, maybe in a future...
'Programing' 카테고리의 다른 글
| 파이썬을 업데이트하는 방법? (0) | 2020.07.16 |
|---|---|
| jar 파일 내부에서 "폴더"리소스를 얻으려면 어떻게해야합니까? (0) | 2020.07.16 |
| Windows 8의 Metro 앱이 같은 컴퓨터의 백엔드 데스크톱 앱과 어떻게 통신 할 수 있습니까? (0) | 2020.07.16 |
| git으로 이름이 바뀐 파일의 로그를 실제로 표시하는 방법은 무엇입니까? (0) | 2020.07.16 |
| history.replaceState () 예제? (0) | 2020.07.16 |