bugGNU Octave - Bugs: bug #52866, print() function doesn't accept...

 
 

bug #52866: print() function doesn't accept '-RGBImage' option

Submitter:  Thomas Aiman <thomasaiman>
Submitted:  Thu 11 Jan 2018 11:27:29 PM UTC
   
 
Category:  Octave Function Severity:  1 - Wish
Priority:  3 - Low Item Group:  Feature Request
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Thu 01 Nov 2018 05:50:44 PM UTC, comment #13: 

@Rik: Yes, I agree the axes lines no being perfectly joined is not crucial since it is only clearly visible when setting a very large line width. I pushed the patch here:

http://hg.savannah.gnu.org/hgweb/octave/rev/8d2b3e3ff182

Marking "Ready for test".

Pantxo Diribarne <pantxo>
Group Member
Thu 01 Nov 2018 03:53:03 PM UTC, comment #12: 

I'm not too concerned about the axes lines not joining.  It's not ideal, but it is a small detail and it would be nice to have this feature.

Rik <rik5>
Group administrator
Thu 01 Nov 2018 11:52:33 AM UTC, comment #11: 

I attached a patch that I'll push soon if no one objects.

The main changes are the addition of print options "-opengl", "-painters" and "-RGBImage" for the qt tookit.
 
In practice, printing to raster formats will now use "getframe" to produce pixels and "imwrite" to save them.

  • Pros:
    • WYSIWYG: EPS font and transparency limitations are no more an issue.
    • In my experience the quality of the output is generally better (for complicated 3D lit surfaces in particular).
  • Cons:
    • gl2ps only features such as primitive sorting and linecap/linejoin handling are not present. For example, zooming the corner of an axes will show the same bad junction as we see on screen with large line width (see bug #39643).


(file #45343)

Pantxo Diribarne <pantxo>
Group Member
Sat 27 Oct 2018 10:38:33 AM UTC, comment #10: 
John W. Eaton <jwe>
Group administrator
Sat 27 Oct 2018 09:04:52 AM UTC, comment #9: 

@jwe: No the patch needs to be reworked to make use of the new _device_pixel_ratio_ property. I'll work on this soon

Pantxo Diribarne <pantxo>
Group Member
Sat 27 Oct 2018 01:55:29 AM UTC, comment #8: 

Regarding the re-definition of "Matlab Compatibility", you might want to mention that on the Octave Maintainer's list.  We're going to have a tough time convincing people that Octave not implementing a feature is not a compatibility issue.

Rik <rik5>
Group administrator
Fri 26 Oct 2018 07:28:29 PM UTC, comment #7: 

Panxto: I see that bug #49053 is closed as fixed now.  Should the patch from comment #6 be applied, or is there something else that should be done now?

Also, I'm retagging this as a feature request instead of a compatibility issue.  I want to reserve the Matlab Compatibility tag for those things that Octave already provides but does in an incompatible (but not necessarily incorrect) way.

http://lists.gnu.org/archive/html/octave-maintainers/2018-08/msg00058.html

John W. Eaton <jwe>
Group administrator
Fri 02 Mar 2018 02:27:06 PM UTC, comment #6: 

I attached a cset in which I implemented "-opengl", "-painters" and "-RGBImage". The "opengl" printing engine uses getframe to produce pixels directly. It is the default for raster formats supported by "imwrite" and doesn't work at all for vector formats.

To have it work quite correctly, I had to scale fixed size objects (text and line width). All this part of the code will be obsoleted and done more accurately when bug #49053 is fixed: the n pixels distance between tick labels and axes can't be scaled from the interpreter.

(file #43437)

Pantxo Diribarne <pantxo>
Group Member
Fri 02 Feb 2018 09:07:27 AM UTC, comment #5: 

PS: I imagine resolution depends on screen DPI, so to complement the previous response:


>> get(0,'ScreenPixelsPerInch')
ans =
    96
>> get(0,'DefaultFigurePosition')
ans =
   520   378   560   420


which explains:


>> r = 200; round([420 560] .* r/96)
ans =
         875        1167
>> r = 400; round([420 560] .* r/96)
ans =
        1750        2333


Amro <amro_octave>
Tue 30 Jan 2018 12:58:36 AM UTC, comment #4: 

@Pantxo: The future of Octave's plotting and printing engine is OpenGL and Qt.  Thus, if you have to ditch support for gnuplot I'm not that concerned.  Changing the release to 'dev'.

Rik <rik5>
Group administrator
Mon 15 Jan 2018 04:07:00 PM UTC, comment #3: 

I ran this in MATLAB:

plot(1:10);
grid on
text(5, 5, 'TEXT', 'fontsize', 20)
a = print('-RGBImage', '-r200');
size(a)
class(a)
imwrite(a, 'r200.png')
b = print('-RGBImage', '-r400');
size(b)
class(b)
imwrite(b, 'r400.png')


size(a) = [875, 1167, 3]
class(a) = 'uint8'
size(b) = [1750, 2333, 3]
class(b) = 'uint8'
imwrite outputs are attached.




Thomas Aiman <thomasaiman>
Sun 14 Jan 2018 09:49:54 AM UTC, comment #2: 

This could be implemented in two ways:

  • use a print command to produce a PNG temporary file and use imread to get the pixel data (slow, works for both gnuplot and opengl)
  • prepare the figure for printing and use "getframe" instead of _opengl_print_ (fast, opengl only). In order to honor the resolution we can probably use interp2  afterwards.


What do those commands return in Matlab:

plot (1:10);
grid on
text (5, 5, "TEXT", 'fontsize', 20)
a = print ('-RGBImage', '-r200')
size (a)
class (a)
imwrite a r200.png
a = print ('-RGBImage', '-r400')
size (a)
class (a)
imwrite a r400.png




Pantxo Diribarne <pantxo>
Group Member
Thu 11 Jan 2018 11:38:41 PM UTC, comment #1: 

Confirmed.  This is a relatively new option which explains why it is unsupported.  I've made this a wish list item to implement.

Rik <rik5>
Group administrator
Thu 11 Jan 2018 11:27:29 PM UTC, original submission:  

From the MATLAB documentation:
https://www.mathworks.com/help/matlab/ref/print.html

cdata = print('-RGBImage'); returns the RGB image data for the current figure. This option differs from screen captures in that all printing features apply to the output. You can also specify the resolution, renderer, '-noui', and fig options with this syntax. However, you cannot specify a Simulink block diagram.


A simple example that works in MATLAB:

figure
peaks
x = print('-RGBImage');


Octave returns the following error:

error: print: unknown option '-RGBImage'
error: called from
    __print_parse_opts__ at line 164 column 9
    print at line 315 column 8


Thomas Aiman <thomasaiman>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #45343:  opengl_print_raster3.patch added by pantxo (24KiB - text/x-patch)
file #43437:  opengl_print_raster.patch added by pantxo (22KiB - text/x-patch)
file #42915:  r200.png added by thomasaiman (23KiB - image/png)
file #42916:  r400.png added by thomasaiman (60KiB - image/png)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by amro_octave (Posted a comment)
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by thomasaiman (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 13 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-12-13 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2018-11-01 pantxo StatusPatch Submitted Ready For Test
    2018-11-01 pantxo Attached File- Added opengl_print_raster3.patch, #45343
    2018-10-26 jwe Priority5 - Normal 3 - Low
        Item GroupMatlab Compatibility Feature Request
    2018-03-02 pantxo Attached File- Added opengl_print_raster.patch, #43437
        StatusConfirmed Patch Submitted
    2018-01-30 rik5 Release4.2.1 dev
    2018-01-15 thomasaiman Attached File- Added r200.png, #42915
        Attached File- Added r400.png, #42916
    2018-01-11 rik5 Severity3 - Normal 1 - Wish
        StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code