Skip to content

Commit

Permalink
Check for images of odd sizes #13
Browse files Browse the repository at this point in the history
Better error message when image has an odd size
  • Loading branch information
jpsacha committed May 4, 2021
1 parent accae4d commit a9cd40a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ object DDFAPD {
* @return reconstructed image as stack of bands
*/
def debayerGR(bay: FloatProcessor, bpp: Int, doRefine: Boolean): ImageStack = {
require(bay.getWidth > 0, s"Image width must be greater than 0, got ${bay.getWidth}.")
require(bay.getWidth % 2 == 0, s"Image width must be even (multiple of 2), got ${bay.getWidth}.")
require(bay.getHeight > 0, s"Image height must be greater than 0, got ${bay.getHeight}.")
require(bay.getHeight % 2 == 0, s"Image height must be even (multiple of 2), got ${bay.getHeight}.")

//
// Horizontal and vertical interpolation of the green channel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ class DDFAPDTest extends AnyFlatSpec with BeforeAndAfter with Matchers {
Utils.compare(cp, cpRef)
}

it should "should throw IllegalArgumentException for images with odd sizes" in {
val bp = new ByteProcessor(347, 440)
assertThrows[IllegalArgumentException] {
DDFAPD.debayerGR(bp, doRefine = true)
}

assertThrows[IllegalArgumentException] {
DDFAPD.debayerGR(bp.convertToFloatProcessor(), 8, doRefine = true)
}
}

before {

val pixels = Array[Short](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

package ij_plugins.debayer2sx

import ij.process.ColorProcessor
import ij.process.{ByteProcessor, ColorProcessor}
import ij_plugins.debayer2sx.DeBayer2Config.{Demosaicing, MosaicOrder}
import ij_plugins.debayer2sx.Utils._
import org.scalatest.BeforeAndAfter
Expand Down Expand Up @@ -76,4 +76,17 @@ class DeBayer2Test extends AnyFlatSpec with Matchers with BeforeAndAfter {
val cp = DeBayer2.stackToColorProcessor(dstStack, bpp)
assert(meanDistance(cp, refCP) <= meanDistanceTolerance * 3)
}

it should "should throw IllegalArgumentException for images with odd sizes" in {
val bp = new ByteProcessor(347, 440)
for (o <- MosaicOrder.values)
assertThrows[IllegalArgumentException] {
DeBayer2.process(bp, DeBayer2Config(mosaicOrder = o, demosaicing = Demosaicing.DDFAPD))
}

for (o <- MosaicOrder.values)
assertThrows[IllegalArgumentException] {
DeBayer2.process(bp, DeBayer2Config(o, Demosaicing.DDFAPDRefined))
}
}
}

0 comments on commit a9cd40a

Please sign in to comment.