problem with imadjust in octave

———- Forwarded message ———-
From: Laurent Hoeltgen <hoeltgman@gmail.com>
To: help-octave@octave.org
Cc:
Date: Mon, 04 Jun 2012 12:08:25 +0200
Subject: Re: Error in imadjust? and image package?
On 06/04/2012 07:50 AM, oka.kurniawan@gmail.com wrote:
> Hi I am trying to use some function in octave-forge package, particularly
> “image-1.0.15”. I can’t seem to get the result I expected. Can some help to
> advise?
>
> %%beginning of code%%
>
> This is my script:
> f=imread(‘einstein.tif’);
> imshow(f)
> g=imadjust(f,[0;1],[1;0]);
> imshow(g);
>
> %% end of code%%
>
> The link to the image is:
> http://scien.stanford.edu/images/labsite/einstein.tif
>
> I got all black result. I would expect the image to be inverted.
>
> I am using Ubuntu 12.04, and install Octave 3.6.1 with image-1.0.15.
>
> Thanks in advance.
>
> Regards,
> Oka
>
>
>
>
> ______________________________

_________________
> Help-octave mailing list
> Help-octave@octave.org
> https://mailman.cae.wisc.edu/listinfo/help-octave

Hi,

On my system, I get:

octave:10> whos
Variables in the current scope:

Attr Name            Size                     Bytes  Class
==== ====            ====                     =====  =====
ans             1×1                          1  uint8
f             256×256                    65536  uint8
g             256×256                    65536  uint8

in particular, f has integer values between 0 and 255 but you tell the
function that it has values between 0 and 1. The following should work:

g = imadjust(double(f)/255,[0,1],[1,0]);

Note that g is a double matrix then.

Regards,
Laurent

Advertisements

Matlab/Octave code to compute centroid of 2d triangular element

It’s a simple code that I use. Sometimes I need to compute the centroid position of a finite element 2D triangle. You can download the code here:

http://ihpcoka.wiki.zoho.com/attach/1.1/Download-Source-Codes/computeCentroidforElems.m

Plotting irregular finite element data in matlab/octave

I am solving a 2D finite element problem and I got x,y,z vectors. The length of these vectors are the number of nodes in my problem. To use the function “mesh”, we need to have x and y coming from “meshgrid”. To plot these data, use the following:

[xi,yi]=meshgrid(x,y);
zi=griddata(x,y,z,xi,yi);
mesh(xi,yi,zi);

Note that xi,yi, and zi are now a matrix.

using update-alternatives

I have several version of octave now, and I do not want to remove the older version yet. Debian system provides a nice command called update-alternatives where it can choose from several alternatives the program you want to use. for example in the case of octave. It will create a symbolic link in /usr/bin/octave that points to /etc/alternatives/octave. This in turns link to the choice of octave we want.

To install a new version of octave to the alternative system:

sudo update-alternatives --install /usr/bin/octave octave ~/Programs/Octave-3.2.4/bin/octave 4

The number at the back is the priority number. Now to choose the default octave we want to load:

sudo update-alternatives --config octave

This will display:
There are 4 alternatives which provide `octave’.

Selection Alternative
———————————————–
+ 1 /usr/bin/octave-2.1.73
2 /home/kurniawano/Programs/Octave3.0.1/bin/octave
* 3 /home/kurniawano/local/bin/octave
4 /home/kurniawano/Programs/Octave-3.2.4/bin/octave

Press enter to keep the default[*], or type selection number: 4
Using ‘/home/kurniawano/Programs/Octave-3.2.4/bin/octave’ to provide ‘octave’.

Of course in the above I choose the newly installed version.

to remove an option, you can use:

sudo update-alternatives --remove octave /home/kurniawano/Programs/Octave3.0.1

Installing Octave 3.2.4 in workstation

Though my previous installation for octave 3.2.2 failed, this time octave 3.2.4 configure just fine. This is what I typed:

./configure --prefix=/scratch/kurniawano/local/ LDFLAGS='-L/scratch/kurniawano/local/lib' CPPFLAGS='-I/scratch/kurniawano/local/include' FFLAGS='-ff2c' LIBS='-lmetis'

After that, I just typed make, and make install. If I didn’t put -lmetis, the make step will give an error, undefined reference to metis.

Installing octave 3.2.3 in CentOs workstation

I tried to install octave 3.2.3 in my CentOS workstation. After I did

./configure --prefix=/scratch/kurniawano/local

It gave an error cannot find the gnu readline 4.2 above. It turns out that I have a local copy of gnu readline 5, so I use

./configure --prefix=/scratch/kurniawano/local LDFLAGS='-L/scratch/kurniawano/local/lib'

where LDFLAGS locate my local libraries. I can finish the configure, but, I got the following warnings:

configure: WARNING: A BLAS library was detected but found incompatible with your
Fortran 77 compiler. The reference BLAS implementation will be used. To improv
e performance, consider using a different Fortran compiler or a switch like -ff2
c to make your Fortran compiler use a calling convention compatible with the way
your BLAS library was compiled, or use a different BLAS library.
configure: WARNING: FFTW library not found. Octave will use the (slower) FFTPAC K library instead.
configure: WARNING: GraphicsMagick++ config script not found. Assuming Graphics Magic++ library and header files are missing, so imread will not be fully functi onal
configure: WARNING: Qhull library not found --- This will result in loss of func tionality of some geometry functions.
configure: WARNING: I didn't find texi2dvi, but it's only a problem if you need to reconstruct the DVI version of the manual
configure: WARNING: "FLTK config script not found. Native graphics will be disa bled."
configure: WARNING:
configure: WARNING: I didn't find the necessary libraries to compile native
configure: WARNING: graphics. It isn't necessary to have native graphics
configure: WARNING: but you will have to use gnuplot or you won't be able
configure: WARNING: to use any of Octave's plotting commands
configure: WARNING:
configure:

NOTE: libraries may be skipped if a library is not found OR
if the library on your system is missing required features.

the warning suggested to use -ff2c flag in the fortran compiler to make the blas call compatible, I added that to the configure command, and that fixed the first warning,

./configure --prefix=/scratch/kurniawano/local LDFLAGS='-L/scratch/kurniawano/local/lib/' FFLAGS='-ff2c'

To solve the warning that it cannot find FFTW library, I create a symbolic link from /usr/lib64/libfftw3f.so.3 to my local libraries, and changed the name to libfftw3f.so. After this, the warning for FFTW disappear.

The QHULL warning disappear after I added in the header file locations using CPPFLAGS.

I let the warning for GraphicsMagick and FLTK. This makes me unable to use imread and native graphics. But that’s ok, I can still use gnuplot for my graphics. But after I typed make, I got the following error:

display.cc:34:22: error: X11/Xlib.h: No such file or directory
display.cc: In member function ‘void display_info::init(bool)’:
display.cc:98: error: ‘Display’ was not declared in this scope
display.cc:98: error: ‘display’ was not declared in this scope
display.cc:98: error: ‘XOpenDisplay’ was not declared in this scope
display.cc:102: error: ‘Screen’ was not declared in this scope
display.cc:102: error: ‘screen’ was not declared in this scope
display.cc:102: error: ‘DefaultScreenOfDisplay’ was not declared in this scope
display.cc:106: error: ‘DefaultDepthOfScreen’ was not declared in this scope
display.cc:108: error: ‘HeightOfScreen’ was not declared in this scope
display.cc:109: error: ‘WidthOfScreen’ was not declared in this scope
display.cc:111: error: ‘XScreenNumberOfScreen’ was not declared in this scope
display.cc:113: error: ‘DisplayHeightMM’ was not declared in this scope
display.cc:114: error: ‘DisplayWidthMM’ was not declared in this scope
make[2]: *** [pic/display.o] Error 1
make[2]: Leaving directory `/scratch/kurniawano/Download/octave-3.2.3/src'
make[1]: *** [src] Error 2
make[1]: Leaving directory `/scratch/kurniawano/Download/octave-3.2.3'
make: *** [all] Error 2

Replacing Matlab saveas function in Octave

It turns out that Octave does not have “saveas” function to store image in jpg. To replace this, I used imwrite,

imwrite(A,filename);