Image extraction extension yields solid black box

Post questions on how to use or achieve an effect in Inkscape.
ScapeGoat
Posts: 40
Joined: Tue Mar 19, 2013 9:36 am

Image extraction extension yields solid black box

Postby ScapeGoat » Sat Mar 23, 2013 5:11 am

I am trying to extract a PNG embedded graphic from a PDF to a PNG file. I want to use the image extraction extension because the native Export function makes it hard to export it in it's existing horizontal & vertical pixel size. However, I'm running into mysterious behaviour. The resulting PNG file is a solid black box. Similary, if I try to copy & paste to Powerpoint as PNG, it's a solid black box. I ensured that the image I've selected is not a grouping of multiple objects.

I also confirmed that it is a PNG embedded graphic:

Code: Select all

<g
       id="g340"
       transform="matrix(225.9588,0,0,147.1672,49.0961,96.3289)"><rect
         x="0"
         y="0"
         width="1"
         height="1"
         transform="matrix(1,0,0,-1,0,1)"
         style="fill:#000000;fill-opacity:1;fill-rule:nonzero"
         mask="url(#mask342)"
         id="rect346" /></g><text

while I am not familiar with SVG code, I saved the PDF source file as SVG, poked around to try, and found the bitmap data for the figure. The key piece seems to be #mask342 above, and I found the following (definition?) near the beginning of the SVG file:

Code: Select all

         id="path338" /></clipPath><mask
       maskUnits="userSpaceOnUse"
       x="0"
       y="0"
       width="1"
       height="1"
       id="mask342"><image
         width="1"
         height="1"
         xlink:href="data:image/png;base64,iVBO...SNIP.../gmCv7N=="
         id="image344" /></mask></defs><sodipodi:namedview

The "SNIP" is a very long stream of ASCII encoded data. I confirmed that this was indeed the PNG bitmap content by deleteing all objects other than the image and re-saving the SVG file.

What would cause the file extraction extension to generate a black box rather than a nice PNG image file?

User avatar
druban
Posts: 1917
Joined: Fri Nov 20, 2009 10:48 pm

Re: Image extraction extension yields solid black box

Postby druban » Sat Mar 23, 2013 7:42 am

Hmm. I believe you asked this question elsewhere? Why start a new thread? Evn if you are still having trouble? The subject seems the same, Brynn will probably move all this to the old topic for other users to get the most benefit in the future.

Although your post was detailed I have a little difficulty with understanding the problem -
you opened the Pdf.
You saved as svg.
You opened the svg.
Everything is still displaying properly at this point?
You select the embedded image.
The status bar at the bottom does not say anything like image, masked, clipped, filtered etc.
If it does, then you do an object menu clip release or mask release and look in the status bar again.
Then you do the extract image and it does not work. Is this correct?

Alternately, the status bar should tell you what the image actual dimensions are (not the dimensions on screen or in the file).
You can select the image and do an export PNG with these dimensions entered for width and height. This may result in a loss of quality.

You can remove the transform by opening the transform dialog, matrix tab, edit current box checked and set fields to A and D=1, B,C,E,F=0.

Just some things to try. I have just tested with a pdf off the web and the extract worked just fine without removing the transform first so that shouldn't be an issue.
You should be able to ctrl select and cut the the image and then paste it in at 'root' level. Sometimes hard to access root level though! Can you do that?
Your mind is what you think it is.

ScapeGoat
Posts: 40
Joined: Tue Mar 19, 2013 9:36 am

Re: Image extraction extension yields solid black box

Postby ScapeGoat » Sat Mar 23, 2013 9:42 am

Hello, druban,

This is actually a different problem. If the two threads get combined, I fear that the two issues will become confused. The previous question was asking about a way to save an embedded rasterized image to PNG in its native horizontal & vertical pixel count. Your solution was to use Exensions->Image->Extract rather than the File->Export function. That worked well, and I noted some caveats for those new to the use of that extension.

This is a different file, different image, and the question isn't about what feature to use to export a PNG with the native pixel count. The problem is that the exported PNG is black.

Some of your suggestions have some effect. For example, it seems the object was a group of 1 object. I didn't make that distinction previously, all I did was repeatedly attempt to ungroup the picture. As it turned out, after the 1st ungrouping, I saw the status line describe the object as clipped. I released it as per your response. That action revealed there was actually a black box sitting on top of the picture. I deleted the black box and the image looked normal, but the image extraction extension did not generate any PNG file. I applied Ungrouped again and the status line showed the object as masked. I released the mask and the object showed as inverted white on black (it should be the opposite). It did extract as a PNG, but in inverted white on black. I applied Filters->Color->Invert, which make it black on white again, but the extracted PNG was still white on black. Sometimes, depending on what things I tried in the many attempts at this, the image might disappear from the Inkscape file and show a big symbol indicated that a linked object could not be found.

Here is what did work, from trial and error. Do all the ungrouping, unclipping, and unmasking needed to get a raw image, and get rid of any extraneous boxes along the way (black or otherwise). Then apply Extensions->Raster->Negate followed by Extensions->Image->Extract to generate a PNG file. My guess as to why this works is that the embedded image is not changed by Filters->Colors->Invert, though the filter may be applied in presenting the display of the object to the Inkscape user on the screen or in generating a printout. In contrast, it seems that Extensions->Raster->Negate does change the underlying image.

About the matrix transformation that you suggested, I read up on what the parameters A, B, C, D are. It all corresponds to the theory I've seen for linear geometric transformations in a 2D plane. However, I suspect (though I've been wrong before) that the HTML manual has an error. They describe A=D=sin(theta) and B=-C=cos(theta). Under that scheme, a rotation of theta=0 (i.e. no net transformation) is specified as A=D=0 and B=-C=1. However, if you set the parameters this way, you actually get a rotation of pi/2 radians counter-clockwise (which is how rotations are traditionally measured in mathematics). Well sin(pi/2)=1 and cos(pi/2)=0. So it could be that a rotation is specified by A=D=cos(theta) and B=-C=sin(theta).

Thanks for your help.

User avatar
ragstian
Posts: 1181
Joined: Thu Oct 11, 2012 2:44 am
Location: Stavanger-Norway

Re: Image extraction extension yields solid black box

Postby ragstian » Sat Mar 23, 2013 11:15 am

Hi.

From other references of PNG's "turning black" (or white), a transparent layer in the PNG gets a solid color when "flattened" or transformed.
Can we get a link to a "black" PNG - to experiment with?

Try saving your PNG as 24 bit - not 16 - if you have that option. (This will retain transparency).

RGDS
Ragnar
Good Luck!
( ͡° ͜ʖ ͡°)
RGDS
Ragnar

User avatar
druban
Posts: 1917
Joined: Fri Nov 20, 2009 10:48 pm

Re: Image extraction extension yields solid black box

Postby druban » Sat Mar 23, 2013 5:03 pm

As you have found out (and as I will boil it down here for other users who might be curious) filters affect the display and export of file elements either embedded or linked wihout actually changing the data, that is, removing the filter restores the element to exactly what it was without any loss. The extensions are exactly the opposite - nonremovable and nonreversible, the image or vector element is actually rewritten after applying the extension.

i'm glad you eventually got things to work. Depending on what program is used to generate a PDF some very weird devices are encountered when disassembling one.

I think what you are noticing in the trasform equations is the program's measuring of angles from a starting point (zero at N) other than what you might expect (zero at E) - what do you have set in your prefs for compass like display of angles? Inkscape may not follow internally what you set there.
Your mind is what you think it is.

ScapeGoat
Posts: 40
Joined: Tue Mar 19, 2013 9:36 am

Re: Image extraction extension yields solid black box

Postby ScapeGoat » Mon Mar 25, 2013 8:35 am

ragstian wrote:Hi.

From other references of PNG's "turning black" (or white), a transparent layer in the PNG gets a solid color when "flattened" or transformed. Can we get a link to a "black" PNG - to experiment with?

Try saving your PNG as 24 bit - not 16 - if you have that option. (This will retain transparency).


Hello Ragstian,

Unfortunately, this is a paper that was obtained through membership access to a forum, so I'm not sure how acceptable it is to post it or a portion of it publically. In case anyone has access to it, it is Figure 1 in:

Ulrich Hauptmanns, "Semi-quantitative fault tree analysis for process plant safety using frequency and probability ranges", Journal of Loss Prevention in the Process Industries 17 (2004) 339–345.

About setting the bit width to 24, how is that setting accessed? There is no such option in the image extraction extension or in the file export operation (nor the corresponding help page). There don't seem to be any relevant options in Document Properties, nor in the preferences for Bitmap, Color Management, or Import/Export. A google for the following doesn't seem to uncover the appropriate control setting.

inkscape png set 16-bit 24-bit
Last edited by ScapeGoat on Mon Mar 25, 2013 8:49 am, edited 1 time in total.

ScapeGoat
Posts: 40
Joined: Tue Mar 19, 2013 9:36 am

Re: Image extraction extension yields solid black box

Postby ScapeGoat » Mon Mar 25, 2013 8:48 am

druban wrote:As you have found out (and as I will boil it down here for other users who might be curious) filters affect the display and export of file elements either embedded or linked wihout actually changing the data, that is, removing the filter restores the element to exactly what it was without any loss. The extensions are exactly the opposite - nonremovable and nonreversible, the image or vector element is actually rewritten after applying the extension.

i'm glad you eventually got things to work. Depending on what program is used to generate a PDF some very weird devices are encountered when disassembling one.

I think what you are noticing in the trasform equations is the program's measuring of angles from a starting point (zero at N) other than what you might expect (zero at E) - what do you have set in your prefs for compass like display of angles? Inkscape may not follow internally what you set there.


I'm not sure. I looked for "compass" in all of the preferences tabs as well as the two indexes of the HTML help pages. I'm not sure if it really matters, though. We're talking about rotations, so there is no vector representation zero (or rather, it doesn't matter what it is). The only thing that matters is clockwise or counteclockwise, and for zero, not even that matters. It doesn't even matter whether we're talking about radians or degress because we're dealing with the sines and cosines. Did I understand your suggestion properly?


Return to “Help with using Inkscape”