Image do not skew

I’m Trying to do a correction in some images (.TIF) that are skew, but having somo issues.
Using Aspose.OCR -> 17.6.0.0

  1. some images are not being corrected.
  2. the images after being process are converted into Black and White images.
  3. If I use a image that was not scanned, I got this error Unable to cast object of type ‘Aspose.Imaging.FileFormats.Dng.DngImage’ to type 'Aspose.Imaging.FileFormats.Tiff.TiffImage
  4. If the image is blank and not skew it change process change the orientation

the code I’m using is, and I attached the images I’m using for testing, just I’m using the images as .TIF
OmrImage omrImage = OmrImage.Load(sourceFilePath);

                System.Drawing.Rectangle area = new System.Drawing.Rectangle(0, 0, omrImage.Width, omrImage.Height);

                GrayscaleAlgorithm grayscaleAlgorithm = new GrayscaleAlgorithm();
                grayscaleAlgorithm.Process(omrImage, area);

                AverageThresholdAlgorithm averageThresholdAlgorithm = new AverageThresholdAlgorithm();
                averageThresholdAlgorithm.Process(omrImage, area);

                SkewCorrectionAlgorithm skewCorrectionAlgorithm = new SkewCorrectionAlgorithm();
                skewCorrectionAlgorithm.Process(ref omrImage, area);

                omrImage.AsBitmap().Save(destinationFilePath);

Point1.jpg (28.9 KB)
Point3.jpg (914.6 KB)
Point4.jpg (1.6 KB)

@ErikaP,

We have investigated the issue at our end. Initial investigation shows that the issue persists for points 1,2 and 3. The issue has been logged into our system with ID OMRNET-551 for further investigation by our Product team. We’ll update you here once there is some information or a fix version available in this regard.

For point #3, DNG image format is not supported. Please share a sample of DNG image and sample code snippet with us. We will look into it and update you about our findings.

Point3.zip (773.0 KB) and the code I’m using:

EncoderValue compression = EncoderValue.CompressionCCITT4;
long colorDepth = 1L;
TiffOptions saveOptions = new TiffOptions(TiffExpectedFormat.Default);
switch (conversionSettings.Compression)
{
case TiffConversionSetting.Compressions.None:
compression = EncoderValue.CompressionNone;
saveOptions.Compression = TiffCompressions.None;
break;
case TiffConversionSetting.Compressions.Ccitt4:
compression = EncoderValue.CompressionCCITT4;
saveOptions.Compression = TiffCompressions.CcittFax4;
break;
case TiffConversionSetting.Compressions.Lzw:
compression = EncoderValue.CompressionLZW;
saveOptions.Compression = TiffCompressions.Lzw;
break;
}
if (saveOptions.Compression == TiffCompressions.CcittFax4)
saveOptions.BitsPerSample = new ushort[] { 1 };
else
{
switch (conversionSettings.ConversionDepth)
{
case TiffConversionSetting.ConversionDepths.Depth1Bpp:
saveOptions.BitsPerSample = new ushort[] { 1 };
break;
case TiffConversionSetting.ConversionDepths.Depth4Bpp:
saveOptions.BitsPerSample = new ushort[] { 4 };
colorDepth = 4L;
break;
case TiffConversionSetting.ConversionDepths.Depth8Bpp:
saveOptions.BitsPerSample = new ushort[] { 8 };
saveOptions.Photometric = TiffPhotometrics.Palette;
saveOptions.Palette = ColorPaletteHelper.Create8Bit();
colorDepth = 8L;
break;
}
}
try
{
using (DicomImage dicomImage = (DicomImage)Image.Load(sourceFilePath))
{
using (RasterImage rasterImage = dicomImage)
{
if (conversionSettings.Brightness <= 0)
conversionSettings.Brightness = 0;
rasterImage.AdjustBrightness(-Convert.ToInt32(conversionSettings.Brightness * 100));
saveOptions.ResolutionSettings = new ResolutionSetting(conversionSettings.Resolution,
conversionSettings.Resolution);
returnList.Add(destinationFilePath);
dicomImage.Save(destinationFilePath, saveOptions);
}
}
}

@ErikaP,

This part of your inquiry is related to Aspose.Imaging. I am moving this query to the respective forum. Where a member from the support team will answer you accordingly.

Yes my mistake I added the wrong code:

try
{
OmrImage omrImage = OmrImage.Load(sourceFilePath);

                System.Drawing.Rectangle area = new System.Drawing.Rectangle(0, 0, omrImage.Width, omrImage.Height);

                GrayscaleAlgorithm grayscaleAlgorithm = new GrayscaleAlgorithm();
                grayscaleAlgorithm.Process(omrImage, area);

                AverageThresholdAlgorithm averageThresholdAlgorithm = new AverageThresholdAlgorithm();
                averageThresholdAlgorithm.Process(omrImage, area);

                SkewCorrectionAlgorithm skewCorrectionAlgorithm = new SkewCorrectionAlgorithm();
                skewCorrectionAlgorithm.Process(ref omrImage, area);

                omrImage.AsBitmap().Save(destinationFilePath);


                // Use empty template or load any existing template
                //OmrEngine engine = new OmrEngine(new OmrTemplate());

                // Get skew degree of the image
                //double degree = engine.GetSkewDegree(omrImage);

                // Rotate image to correct skew
                //engine.RotateImage(ref omrImage, degree);

                //omrImage.AsBitmap().Save(destinationFilePath);

                returnList.Add(destinationFilePath);
                return returnList;
            }

In the above reference you have mentioned DNG image format. The image you have shared is a TIFF image. Please share the DNG image that is producing error. We have tested the “Point3.tif” image file and we are unable to reproduce the error as mentioned above.