Please advise what to do to make the rgb2gray work in Octave.
I found this thread, but still I would like to use the rgb2gray functionality instead of manually calculating for each color channel.
The code that I run:
I = imread('smile.jpg');
G = rgb2gray(I);
The error I get:
error: 'rgb2gray' is undefined near line 10 column6
Additional:
Octave version: 3.6.4
Image package is installed. Version: 2.0.0.
The 'rgb2gray.m' is installed in C:\Octave\share\octave\packages\image-2.0.0
Thanks,
The problem is that you didn't load your packages. When you type pkg list you can find which ones are loaded by an asterisk in front of their names. Load a package with pkg load image.
Having to load a packages is that thing that most users find strange but if you compare with other languages, such as Python, Perl, or C++, would you expect them to import, use, or #include every libraries available in the system by default? See Octave's FAQ for more details.
The function rgb2ntsc has historically been part of Octave (I mean historically, since 1994). However, since Octave version 4.4 (released in 2018), the function was moved from Octave to the Octave Forge image package. It is part of the Octave Forge image package since its 2.8.0 version (released in 2018).
Basically, how to use rgb2ntsc depends on what version you have:
Octave >= 4.4.0
You need to install and load the image package version 2.8.0 or later (the latest is 2.12.0).
octave> pkg install -forge image
octave> pkg load image
unfortunately, it did not work for me. So I use the code, and it works. which is from Octave rgb2ntsc missing in latest version
function yiq_img = rgb2ntsc(rgb_img)
%RGB2NTSC Transform a colormap or image from red-green-blue (RGB)
% color space to luminance-chrominance (NTSC) space.
% The input may be of class uint8, uint16, single, or double.
% The output is of class double.
% https://octave.sourceforge.io/octave/function/rgb2ntsc.html
if isa(rgb_img, 'uint8') || isa(rgb_img, 'uint16') || ...
isa(rgb_img, 'double')
red = rgb_img(:, :, 1);
green = rgb_img(:, :, 2);
blue = rgb_img(:, :, 3);
y = 0.299 * red + 0.587 * green + 0.114 * blue;
i = 0.596 * red - 0.274 * green - 0.322 * blue;
q = 0.211 * red - 0.523 * green + 0.312 * blue;
yiq(:, :, 1) = y;
yiq(:, :, 2) = i;
yiq(:, :, 3) = q;
yiq_img = double(yiq);
else
error('Input image datatype is not supported')
end
end
I am viewing the week5 lecture notes by Andrew Ng. AI machine learning course. https://www.coursera.org/learn/machine-learning/resources/EcbzQ
refer to: Octave rgb2ntsc missing in latest version
Related
I just started using GNU Radio, I must say I am quite a noob but I have some background on RF related stuff.
Here's the thing:
I recorded a file that I now want to repeat through my HackRF and GNU Radio.
This is the exact settings for the filter:
The settings you see are casual (since I cannot get it working I started testing with random values).
This is the error I get:
Executing: /usr/bin/python3 -u /home/scare/LAB/RadioFrequencies/GNU Radio/reply_433.py
gr-osmosdr 0.2.0.0 (0.2.0) gnuradio 3.8.2.0
built-in sink types: uhd hackrf bladerf soapy redpitaya file
[INFO] [UHD] linux; GNU C++ version 11.1.0; Boost_107600; UHD_4.0.0.0-0-unknown
Using HackRF One with firmware 2017.02.1
Traceback (most recent call last):
File "/home/scare/LAB/RadioFrequencies/GNU Radio/reply_433.py", line 211, in <module>
main()
File "/home/scare/LAB/RadioFrequencies/GNU Radio/reply_433.py", line 187, in main
tb = top_block_cls()
File "/home/scare/LAB/RadioFrequencies/GNU Radio/reply_433.py", line 137, in __init__
firdes.high_pass(
File "/usr/lib/python3.9/site-packages/gnuradio/filter/filter_swig.py", line 124, in high_pass
return _filter_swig.firdes_high_pass(*args, **kwargs)
RuntimeError: firdes check failed: 0 < fa <= sampling_freq / 2
Done (return code 1)
Where obviously the interesting part is the RuntimeError: firdes check failed: 0 < fa <= sampling_freq / 2
Unfortunately, I don't get what that 'fa' stands for.
Any idea?
Cheers
I just got done solving this same error. The error is caused by a filter's Cut-off and transition parameters being set incorrectly (in my case far too large). GNU radio handles the variable 'samp_rate' differently for each block and filters seem to interpret it was a point to center the filter on (that's my take on it so don't quote me).
I also looked in the source code and can't find anything helpful on 'fa'
So try adjusting your cutoff to be something below samp_rate and make your transition width something to the tune of 250e3. I used GUI sliders to set the filter how I liked and I will make these permanent in the final version.
Screen Cap of Settings Here
Slider Settings For Both Sliders
Mike Ossmann's "SDR with HackRF One, Lesson 10 - Filters helped" me out here. Also just a great SDR lecture series for GNU radio if you haven't come across them yet. (just make sure to use the QT GUI).
I hope this helped. I am pretty new to GNU so sorry if the explanation is a little half-baked.
fa is the cutoff_frequency in the function that is throwing the error message. The cutoff frequency has to be greater than 0 and no more than the Nyquist limit. There are some functions called sanity_check_xxx (xxx being whether one cutoff or 2, i.e. bandpass, and optionally c for complex) around line 750 in gr_filter/lib/firdes.cc in the GNU Radio repository on GitHub.
In the question the samp_rate would need to be at least 800MHz to support a high pass cutoff of 400Mhz. As far as I can tell sample rate is used the same way in these filter functions as anywhere else in GNU Radio.
I ran into the same error message because I used 'firdes.band_passinstead offirdes.complex_band_pass` and the low cutoff was negative, which it should be for the complex band pass filter.
I have a very short script that I'm running in Octave and I want to read a user specified text file. It works on my 64-bit laptop, but not on my 32-bit one. The Octave version is 3.2.2.
plotinfra.m
filename=uiputfile
data=load(filename);
plot(data(:,1),data(:,2));
On my other laptop, this brings up a filesystem menu where I can choose the specific file to load. On this laptop, I see this error message instead:
error: uiputfile undefined near line 1 column 19 error: called from: error: plotinfra.m at line 1, column 17
If I hardcode filename with a path it works. I also tried using uigetfile and that did not work either.
Version 3.2.2 of Octave was released in 2009. When I enter edit uiputfile in Octave, at the top of the file I see the line:
## Copyright (C) 2010-2019 Kai Habel
Thus, it seems that this function was created after your release of Octave. This is the reason you get a "uiputfile undefined" error message.
You will have to upgrade your version of Octave to use this function.
I'm using Ubuntu 18.04 64Bit Linux Octave 4.2.2 see if this works for you. It will store the filename in the variable file_name and the path location in the variable path_dir
% create your dataset (exampledata)
x = (-1:0.1:1);
y = sin(x);
data = zeros(length(x),2);
data(:,1) = x;
data(:,2) = y;
% save data to file (your textfile)
save('-ascii','data2.txt','data');
%load textfile
%data2 = load('data2.txt'); %hard coded
[file_name,path_dir] = uigetfile('*.txt'); %pops up uibox choose data2.txt
data2 = load(strcat(path_dir,file_name)); %loads the file and the data
%plot data
plot(data2(:,1),data2(:,2));
I am using log2 function in Octave to calculate log2 values of a simple array.
>> x = [1:5]
x =
1 2 3 4 5
>> log2(x)
error: invalid use of script D:\All_Data\my_data\backup3\backup3\tech\DSP\log2.m in index expression
I am not sure why Octave is bailing out with error in this case ...
You probably have a script that is called log2.m in your running directory, which prevents octave from calling its own log2 function.
I assume that is the case because D:\All_Data\my_data\backup3\backup3\tech\DSP\log2.m
doesn't look like a path where standard octave library functions would be installed.
I recommend changing the name of the script in your running directory.
Such a simple question to have wasted an hour or two of my time. The Octave docs allude to setting the interpreter to tex and never say how to do it. I've looked on line and through stackoverflow and haven't found how to do this. I've also looked at the .octaverc files and have seen nothing that would indicate how to turn on the tex edit function. I am using Debian GNUOctave version 4.0.0. Please help.
Gary Roach
The interpreter property is set to "tex" per default for axes, line, text, patch and surface. So changing interpreter makes only sense if you want to switch to "none":
set (findobj (gcf, "-property", "interpreter"), "interpreter", "none")
This sets "interpreter"="none" for al children of the current figure.
If you want to have some fancy latex stuff in your plots and not only simple tex commands you can render it with latex:
close all
graphics_toolkit fltk
sombrero ();
title ("The sombrero function:")
fcn = "$z = \\frac{\\sin\\left(\\sqrt{x^2 + y^2}\\right)}{\\sqrt{x^2 + y^2}}$";
text (0.5, -10, 1.8, fcn, "fontsize", 20);
print -depslatexstandalone sombrero
## process generated files with pdflatex
system ("latex sombrero.tex");
## dvi to ps
system ("dvips sombrero.dvi");
## convert to png
system ("gs -dNOPAUSE -dBATCH -dSAFER -sDEVICE=png16m -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r100x100 -dEPSCrop -sOutputFile=sombrero.png sombrero.ps")
which gives:
I'm trying to execute the simple example from the Sympy's autowrap module that includes matrix/vector product with the Cython langage (since I do not have gfortran installed):
import sympy.utilities.autowrap as aw
from sympy.utilities.autowrap import autowrap
from sympy import symbols, IndexedBase, Idx, Eq
A, x, y = map(IndexedBase, ['A', 'x', 'y'])
m, n = symbols('m n', integer=True)
i = Idx('i', m)
j = Idx('j', n)
instruction = Eq(y[i], A[i, j]*x[j])
matvec = autowrap(instruction, language='C',backend='cython')
I'm on OSX 10.9.4, with the anaconda distribution for python 2.7, sympy 0.7.6.1 and cython 0.23.2.
I get the following (known) error: fatal error: 'numpy/arrayobject.h' file not found
It seems to be a systematic error, and one needs to include the appropriate numpy's header target in the setup file attached to the compilation process of cython as suggested here.
How to get rid form this issue in an autowrap context?
It seems this is a bug fixed here, but it does not work for me... Is this bug fix included in sympy's realease 0.7.6.1?
Any idea?
This was a bug and is now fixed. See this pull request:
https://github.com/sympy/sympy/pull/8848
If you use the development version of SymPy, it should work. Else you could have autowrap spit the files out to a temporary directory, add the correct include statement to the generated files, and manually compile the code.