scilab - Implementing log function on images - image-processing

I want to apply a log function to images. But it fails showing this error: function is not defined on this type of argument.
uk=imread('image.jpg');
result=log(uk(:,:,1));

I think your problem is that imread returns a matrix of uint8 type. To apply log, you should convert it to double. There are at least 2 ways to do this, one built in, and one from SIVP:
clc;
clear;
im = imread("d:\Attila\PROJECTS\Scilab\Stackoverflow\mixer_crop.jpg");
//imshow(im);
disp(typeof(im(:,:,1)),"Original type:");
//use double
M = double(im(:,:,1));
disp(typeof(M),"Modified type:");
result=log(M);
//imshow(uint8(M));
//use im2double
M2 = im2double(im);
disp(typeof(M2(:,:,1)),"Modified type 2:");
result=log(M2(:,:,1));
//imshow(im2uint8(M2));

Related

cv2.addweight() throws error: functions have different types, the output array type must be explicitly specified in function 'cv::arithm_op'

I'm using opencv-python in VSCODE, I create 2 2-dimensions arrays of the same type and same size. but I got this error when it executes the method cv2.addWeighted, I see other people are asking the same question, but their problem is the different data type. However, I have double checked the data type in my code, they are the same (np.uint8).
img01 = np.ones((200, 200), dtype=np.uint8) * 1000
img02 = np.ones((200, 200), dtype=np.uint8) * 100
weightedImg = cv2.addWeighted(img01,0.6,img02,0.4,3)
error: (-5:Bad argument) When the input arrays in add/subtract/multiply/divide functions have different types, the output array type must be explicitly specified in function 'cv::arithm_op'
I would like to know what's wrong in my code. thanks.

how to cv2.imencode and imdecode (jpeg) for diffret QF values?

I need to use open cv functions: cv2.imencode,cv2.imdecode to compress (jpeg) and decompress (jpeg) for different QF values.
The picture is 'bridge.ppm' from https://imagecompression.info/test_images/
I've tried:
bridge = cv2.imread('./bridge.ppm')
bridge_en = cv2.imencode('.jpeg', bridge)
bridge_de = cv2.imdecode('.jpeg', bridge_en)
cv2.imshow('image',bridge_de)
but I'm getting an error in the 2nd line saying: "Expected Ptr<cv::UMat> for argument 'buf'".
Also, how can I change and test different QF values?
Please take a look to the documentation for imencode and imdecode
imencode returns two values, the encoded buffer is the second one. And imdecode accepts the encoded buffer and a flag. So:
bridge = cv2.imread('./bridge.ppm')
bridge_en = cv2.imencode('.jpeg', bridge)[1] # you need the second value
bridge_de = cv2.imdecode(bridge_en, cv2.IMREAD_UNCHANGED) # or any other flag, same as 'imread'
cv2.imshow('image',bridge_de)

How do i format a numeric number to Exponential form in flutter

I am trying to format a numeric number to display in exponential form. e.g 140500.45 as 1.4050045E5 using NumberFormat class in Dart. How do i go about this in flutter.
The following is what i have tried so far;
`NumberFormat numbFormat = NumberFormat("E", "en_US");
returnFormat = numbFormat.format(numericNumber);
print(returnFormat);`
Thanks.
This is how i eventually solved the problem;
double resultme = 140500.45;
double myreturnFormat = resultMe;
returnFormat = myreturnFormat.toStringAsExponential();
print(returnFormat);
The output is now correctly 1.4050045e+5
What i was initial doing wrong is supplying double argument to toStringAsExponential() method. The method requires no argument to return the results without rounding up the result. If you desire to return result such as 1.405e+5, do it like so;
myreturnFormat.toStringAsExponential(3);
The output will be 1.405e+5
Hope this help someone.

no operator [] match these operands

I am adapting an old code which uses cvMat. I use the constructor from cvMat :
Mat A(B); // B is a cvMat
When I write A[i][j], I get the error no operator [] match these operands.
Why? For information: B is a single channel float matrix (from a MLData object read from a csv file).
The documentation lists the at operator as being used to access a member.
A.at<int>(i,j); //Or whatever type you are storing.
first, you should have a look at the most basic opencv tutorials
so, if you have a 3channel, bgr image (the most common case), you will have to access it like:
Vec3b & pixel = A.at<Vec3b>(y,x); // we're in row,col world, here !
pixel = Vec3b(17,18,19); // at() returns a reference, so you can *set* that, too.
the 1channel (grayscale) version would look like this:
uchar & pixel = A.at<uchar>(y,x);
since you mention float images:
float & pixel = A.at<float>(y,x);
you can't choose the type at will, you have to use, what's inside the Mat, so try to query A.type() before.

Custom Array Functions in Open Office Calc

Could someone please tell me how to write a custom function in Open Office Basic to be used in Open Office Calc and that returns an array of values. An example of one such built-in function is MINVERSE. I need to write a custom function that populates a range of cells in much the same way.
Help would be much appreciated.
Yay, I just figured it out: all you do is return an array from your macro, BUT you also have to press Ctrl+Shift+Enter when typing in the cell formula to call your function (which is also the case when working with other arrays in calc). Here's an example:
Function MakeArray
Dim ret(2,2)
ret(0,0) = 1
ret(1,0) = 2
ret(0,1) = 3
ret(1,1) = 4
MakeArray = ret
End Function
FWIW, damjan's MakeArray function returns a Variant containing an array, I think. (The type returned by MakeArray is unspecified, so it defaults to Variant. A Variant is a container with a descriptive header, apparently cast as needed by the interpreter.)
Almost, but not quite, the same thing as returning an array. According to http://www.cpearson.com/excel/passingandreturningarrays.htm, Microsoft did not introduce the ability to return an array until 2000. His example [ LoadNumbers(Low As Long, High As Long) As Long()] does not compile in OO, flagging a syntax error on the parens following Long. It appears that OO's Basic emulates the pre-2k VBA.

Resources