Gray scale and Blank image detection


#1

Hi,


Is there any functionality to detect Gray scale and blank page image using Aspose.Imaging SDK?

Thanks,
Dhivya

#2

Hi Dhivya,

Thanks for inquiring Aspose.Imaging.

I have observed your requirements and like to share that even if a 32 or 24 bit image internally can have RGB distribution to make an image a gray scaled. So, in order to verify the image to be a gray scaled, you need to traverse every image pixel and verify if that is gray scaled or not.

Similarly, in order to check a blank image, you need to traverse every pixel and compare the two consecutive pixels. If there is any difference between two consecutive pixels, we cannot call image to be blank. Attach please find the sample code and sample images for verifying gray scale and blank images. I hope the shared information will be helpful.


Many Thanks,


#3

Thank you Mudassir.


The code samples are working fine.

#4

Hi,
me too, I need to check if a page is blank.
Can you share the sample code to check if a page is blank?

I tried with this code:

Public Function PageIsBlank(image As Stream, minBlackPixels As Integer) As Boolean
		Using img As Aspose.Imaging.Image = Aspose.Imaging.Image.Load(image)
			Dim r As Aspose.Imaging.RasterImage = TryCast(img, Aspose.Imaging.RasterImage)
			Dim width As Integer = r.Width
			Dim height As Integer = r.Height
			Dim pixels() As Aspose.Imaging.Color = r.LoadPixels(New Aspose.Imaging.Rectangle(0, 0, width, height))
			Dim count As Integer = 0
			Dim blankLimit As Integer = GetRGB(Aspose.Imaging.Color.White)
			' Considered blank if unded 99%
			blankLimit = CInt(blankLimit * 0.99)
			For Each p As Aspose.Imaging.Color In pixels
				If GetRGB(p) <= blankLimit Then count += 1
				If count >= minBlackPixels Then Exit For
			Next
			If count < minBlackPixels Then
				Return True
			End If
			Return False
		End Using
	End Function

	Private Function GetRGB(c As Color) As Integer
		Dim rgb As Integer = 0
		rgb += CInt(c.R)
		rgb += CInt(c.G)
		rgb += CInt(c.B)
		Return rgb
	End Function

#5

@itconsult.developer,

I have observed the sample code. Have you found any issue while using this code. Can you please share the source image that you need to verify so that I may investigate this further on my end.


#6

No issue with that code… My question wanted to be only: is there an “official” (or better) way to check if a page is blank?
Anyway, thank you.


#7

@itconsult.developer,

Thank you for sharing your feedback. As I have shared earlier in my previous post as well that one need to traverse every pixel inside the image and in case of any change in pixel comparison the image shall be considered not as blank. Otherwise in case of no change in all pixels comparisons the image will be considered blank. This is only way to check the image.