Problem with black image while adding text

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
zwindvincent

Problem with black image while adding text

Post by zwindvincent »

Dear all,

I have faced the following problem.

When I try the following command:

convert inputimage.tif -gravity NorthEast -pointsize 55 -draw "text 150,45 'Hello World'" outputimage.tif

the output image is a fully black image rather than a image with text.The inputimage.tif is a Bi-level image.

However , the text can be added when I using another GrayScale tif image (inputimage2.tif ) , the text can be added.

Thus, I would like to convert the inputimage.tif to Grayscale such that text could be added on it. I use the following command:

convert -type Grayscale inputimage.tif grayimage.tif

the command could run with no error but the when i check the grayimage.tif (i use identify -verbose grayimage.tif ) , the type is still Bilevel.

So, could anyone helps me to change a Bilevel tif image to Grayscale image?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Problem with black image while adding text

Post by anthony »

I think you may be looking at the wrong cause.
Internally Im will see the image the same way regardless of the image input. As such it is more likly that it is reading the TIF image incorrectly than any difference in image type.

The most likely reason the tif image is black, is because it needs some info on the polarity of the input image.. try adding

Code: Select all

   -define quantum:polarity=min-is-white
or

Code: Select all

   -define quantum:polarity=min-is-black
to the command BEFORE the TIFF image read argument.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
zwindvincent

Re: Problem with black image while adding text

Post by zwindvincent »

Dear Sir,

After using the define method, I find that the result is still the same. ( i.e. black image )

I am using the following commands:

convert -define quantum:polarity=min-is-white inputimage.tif -gravity NorthEast -pointsize 55 -draw "text 150,45 'Hello World'" outputimage.tif

convert -define quantum:polarity=min-is-black inputimage.tif -gravity NorthEast -pointsize 55 -draw "text 150,45 'Hello World'" outputimage.tif

May I know what's wrong with my code?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with black image while adding text

Post by fmw42 »

Try including a fill color for your text. The default is probably black.

add -fill white before your -draw
zwindvincent

Re: Problem with black image while adding text

Post by zwindvincent »

still can't work ... , could anyone help me? Thx.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with black image while adding text

Post by fmw42 »

you need to provide your image for others to analyze
zwindvincent

Re: Problem with black image while adding text

Post by zwindvincent »

Sorry , the photo is a confidential file which can't be released at this moment. However , here is the information (using the identity command ) about the photo:

Image: image.tif
Format: TIFF (Tagged Image File Format)
Class: PseudoClass
Geometry: 2480x3507
Type: Bilevel
Endianess: LSB
Colorspace: Gray
Channel depth:
Gray: 1-bit
Channel statistics:
Gray:
Min: 0 (0)
Max: 1 (1)
Mean: 0.939211 (0.939211)
Standard deviation: 0.238943 (0.238943)
Colors: 2
Histogram:
528706: ( 0, 0, 0) black
8168654: (255,255,255) white
Rendering intent: Undefined
Resolution: 300x300
Units: PixelsPerInch
Filesize: 49.3203kb
Interlace: None
Background color: white
Border color: #DFDFDF
Matte color: grey74
Page geometry: 2480x3507+0+0
Dispose: Undefined
Iterations: 0
Compression: Group4
Orientation: TopLeft
Comment: IMAGE MAKER: Spittin' Image Software Inc. V1.0
Signature: a46e59244c9420564a51be7f286936fe5ea9001a55fbccc15f0e47c07b939fad
Tainted: False
User time: 0.156u
Elapsed time: 0:01
Pixels per second: 44.1195mb
Version: ImageMagick 6.2.8 08/02/06 Q16 http://www.imagemagick.org

And here is another information for another photo which could be added the text:

Image: image2.tif
Format: TIFF (Tagged Image File Format)
Class: PseudoClass
Geometry: 2480x3507
Type: Grayscale
Endianess: MSB
Colorspace: Gray
Channel depth:
Gray: 8-bit
Channel statistics:
Gray:
Min: 0 (0)
Max: 255 (1)
Mean: 239.307 (0.938459)
Standard deviation: 61.2754 (0.240296)
Colors: 256
Histogram:
528599: ( 0, 0, 0) black
6596: ( 1, 1, 1) #010101
8142180: (255,255,255) white
19985: (254,254,254) #FEFEFE
Rendering intent: Undefined
Resolution: 300x300
Units: PixelsPerInch
Filesize: 497.215kb
Interlace: None
Background color: white
Border color: #DFDFDF
Matte color: grey74
Page geometry: 2480x3507+0+0
Dispose: Undefined
Iterations: 0
Compression: RLE
Orientation: TopLeft
Comment: IMAGE MAKER: Spittin' Image Software Inc. V1.0
Document: form_001.tif
Signature: 72f28d8fd115e3471b3cc82aa29e77bc5aae2d52f90a289fe7c60ebf290e4fee
Software: ImageMagick 6.2.8 08/02/06 Q16 http://www.imagemagick.org
Tainted: False
User time: 0.141u
Elapsed time: 0:01
Pixels per second: 58.8256mb
Version: ImageMagick 6.2.8 08/02/06 Q16 http://www.imagemagick.org
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with black image while adding text

Post by fmw42 »

have you tried to convert the image with -type Palette or -type Grayscale?

you can also try changing the endian from LSB to MSB via -endian MSB

see

http://www.imagemagick.org/script/comma ... s.php#type
http://www.imagemagick.org/script/comma ... php#endian

try

convert inputimage -colorspace Gray -type Grayscale -endian MSB outputimage
zwindvincent

Re: Problem with black image while adding text

Post by zwindvincent »

yes , as you mentioned , I have tried the commands as you post.

However , i can successfully change the colorspace , the endian , but can't change the type to Grayscale. So, that's why from the very beginning I ask for how to change a bilevel image to grayscale image.

Any more suggestions? Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with black image while adding text

Post by fmw42 »

zwindvincent wrote:yes , as you mentioned , I have tried the commands as you post.

However , i can successfully change the colorspace , the endian , but can't change the type to Grayscale. So, that's why from the very beginning I ask for how to change a bilevel image to grayscale image.

Any more suggestions? Thanks.

I think you need to report this to the Bugs forum. But they will likely want an example image. But you can send it to them proprietarily so the IM people are the only ones to see it. Just report it and ask if you can send via private message.
jaffamuffin
Posts: 59
Joined: 2009-01-30T03:46:08-07:00

Re: Problem with black image while adding text

Post by jaffamuffin »

Hi there.

I have a simliar issue. I am trying to draw a white rectangle on to a Bilevel G4 tiff, and it is outputting a 4 bit per pixel image with 50% covered in black. And the white is turned grey.

convert 0001.tif -fill white -draw "rectangle 2016,1057 2286,2497" -compress group4 -define polarity=min-is-white c:\out.tif


Howvere if I canvoert to JPG and perform the same operation as above it works.

I can prepare sample for further inspection if required?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Problem with black image while adding text

Post by magick »

We cannot reproduce the problem with ImageMagick 6.4.9-3, the latest release. Can you post a URL to your 0001.tif image so we can see if the problem is specific to your image?
jaffamuffin
Posts: 59
Joined: 2009-01-30T03:46:08-07:00

Re: Problem with black image while adding text

Post by jaffamuffin »

I installed the latest release 6.4.9-3 2009-02-05 Q8 and the problem is fixed.

I was previously using 6.3.4 06/01/07 Q8.
Post Reply