"imshowpair" matlab function alternative for octave - matlab

are there "imshowpair" matlab function alternative in octave function or method?
when try it?
error: 'imshowpair' undefined near line 15, column 15
The 'imshowpair' function belongs to the image package from Octave Forge
but has not yet been implemented.
Please read <https://www.octave.org/missing.html> to learn how you can
contribute missing functionality.
the code:
close all
clear
clc
i=imread('1.jpg');
##BW=imbinarize(i);
BW=im2bw(i);
figure;
imshow(BW);
title('Binary image')
x=input("Enter whatever u want")
cc8=bwconncomp(BW,x);
L8=labelmatrix(cc8);
RGBLabel=label2rgb(L8,'jet','k','shuffle');
figure
imshowpair(L8,RGBLabel,'montage');
title(['lable img with ',int2str(x),'connctivity']);
imwrite(RGBLabel,'label.png');
Best Regards

Related

Problem with implementing eigenface method based on a sample source code

I am imitating implementation of eigenface method for face recognition in MATLAB. I am using the sample code which is briefly discussed in the following video:
https://www.youtube.com/watch?v=V-Miq_k3BJk
The sample code is attached in the following:
loaded_Image=load_img();
random_Index=round(400*rand(1,1));
random_Image=loaded_Image(:,random_Index);
rest_of_the_images=loaded_Image(:,[1:random_Index-1 random_Index+1:end]);
image_Signature=20;
white_Image=uint8(ones(1,size(rest_of_the_images,2)));
mean_value=uint8(mean(rest_of_the_images,2));
mean_Removed=bsxfun(#minus,rest_of_the_images,uint8(single(mean_value)*single(white_Image)));
L=single(mean_Removed)'*single(mean_Removed);
[V,D]=eig(L);
V=single(mean_Removed)*V;
V=V(:,end:-1:end-(image_Signature-1));
all_image_Signature=zeros(size(rest_of_the_images,2),image_Signature);
for i=1:size(rest_of_the_images,2);
all_image_Signature(i,:)=single(mean_Removed(:,i))'*V;
end
subplot(121);
imshow(reshape(random_Image,112,92));
title('Looking for this Face','FontWeight','bold','Fontsize',16,'color','red');
subplot(122);
p=random_Image-mean_value;
s=single(p)'*V;
z=[];
for i=1:size(rest_of_the_images,2)
z=[z,norm(all_image_Signature(i,:)-s,2)];
if(rem(i,20)==0),imshow(reshape(rest_of_the_images(:,i),112,92)),end;
drawnow;
end
[a,i]=min(z);
subplot(122);
imshow(reshape(rest_of_the_images(:,i),112,92));
title('Recognition Completed','FontWeight','bold','Fontsize',16,'color','red');
I do not know why we use "image_signature" variable in our code. I can not understand what value for this variable is required. can anyone help?
Best regards,
Thank you

getpts MATLAB returns unrecognized function or variable 'getpts'

i'm trying to use getpts to choose points in the current figure using the mouse. However, when i run it, i'm getting the error "unrecognized function or variable 'getpts'."
Here's my code
for i=1:n
im = imread([read_path 'IMG_' num2str(i+t) '.jpg']); %Get image
figure
imshow(im)
[x,y] = getpts; %returns error
end
Any idea why that's happening?
Note: I'm using the free trial version of Matlab
I'd appreciate the help!
From the docs, getpts is in the image processing toolbox.
This isn't always obvious, you can infer it from the docs link itself:
mathworks.com/help/images/ref/getpts.html
(where a built-in would be something like mathworks.com/help/matlab/ref/sum.html)
You can also see it's nested under the image processing toolbox in the side-bar on that page.
In your trial installation of MATLAB you likely don't have this toolbox. You might know from the install process, or you could check whether the toolbox folder exists in the installation directory, e.g.

MATLAB: findpeaks function

I'm using MATLAB 2013a and trying to find peak points of my data. When I tried code example given in
Find Peaks with Minimum Separation
I am getting the following error:
Error using uddpvparse (line 122)
Invalid Parameter/Value pairs.
Error in findpeaks>parse_inputs (line 84)
hopts = uddpvparse('dspopts.findpeaks',varargin{:});
Error in findpeaks (line 59)
[X,Ph,Pd,Th,Np,Str,infIdx] = parse_inputs(X,varargin{:});
I tried simple x and y vectors and got the same error. What can be the problem?
I have the same problem as you (R2013a on OSX) with the example by the Mathworks. For some reason it seems we can't use findpeaks with the x-and y-data as input arguments, We need to call the function with the y data and use the [peaks,locations] output to get the peaks/plot them.
It looks like in R2014b they changed some stuff about findpeaks that does not work with older versions...like calling the function with not output argument in R2014b plots the data/peaks without any additional step...but it does not for earlier versions.
Anyhow here is a way to workaround the problem. Call findpeaks with a single input argument (y data that is, you can use property/value pairs as well) and use the indices (locations) to show the peaks:
clc
clear
load sunspot.dat
year = sunspot(:,1);
avSpots = sunspot(:,2);
[peaks, locations] = findpeaks(avSpots)
plot(year,avSpots)
hold on
scatter(year(locations),avSpots(locations),40,'filled')
hold off
Output:
It might be worthwhile to contact The Mathworks about this. Hope that helps!

SSIM Coding Error

I have some questions. I try to follow some coding from Mathworks:
I = imread('cameraman.tif');
ssimValues = zeros(1,10);
qualityFactor = 10:10:100;
for i = 1:10
imwrite(I,'compressedImage.jpg','jpg','quality',qualityFactor(i));
ssimValues(i) = ssim(imread('compressedImage.jpg'),I);
end
I just change the image file which is a.jpg and b.jpg but I get this error from MATLAB:
Undefined function 'ssim' for input arguments of type 'uint8'
Error in SSIMTesting (line 6)
ssimValues(i) = ssim(imread('logohalal1.jpg'),i);
Why is that ? Can someone help me explain the code and the error ? Sorry because I'm new in MATLAB.
Thank you.
MATLAB release notes for the Image Processing Toolbox shows that this function was new to R2014a. If you have an older version of MATLAB, or you don't have that toolbox, you don't have it. This sort of issue can be avoided by using only examples found in the help on your local installation of MATLAB rather than the online help.
To check your version of MATLAB and installed toolboxes, type ver at the command line.
To check if a function can be found on your MATLAB path, you can use which, e.g. which ssim

Running Functions in GUI matlab

Continuing my struggle against GUI's, I have run into another road block.
Ive successfully created a button that opens a file as a string, and places it in a text box in my GUI like so.
[filename, pathname] = ...
uigetfile({'*.m';'*.mdl';'*.mat';'*.*'},'File Selector');
set(handles.Textbox1, 'string', fullfile(pathname,filename));
But now I cannot seem to use a function on the acquired file. Ive tried doing
str = get(handles.Textbox1,'string');
Histogram(str); %Histogram is a function that I created.
But im getting the following errors
??? Error using ==> Histogram Too many input arguments.
Error in ==> VarunGUI>pushbutton2_Callback at 94 Histogram(str);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> VarunGUI at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
#(hObject,eventdata)VarunGUI('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
Is my code for calling the function to blame, or is the function itself? I'm having trouble understanding how to alter the function to work on the called image, so that may be my problem, the function begins with the following code.
function Histogram
clear;
clc;
fid = fopen('');
myimage = fread(fid, [512, 683], '*uint8');
fclose(fid);
Is there a certain variable I need to place in the '' to make the GUI act in the manner to which I would like it? Question ran a little long, but please tell me if there is anything else you need to see in order to assist me, any guidance or tips would be great. Thanks!
Your Histogram function doesn't have an input, so it fails when you call it : Histogram(str)
You're problem is that call Histogram and pass it str:
Histogram(str)
But you don't define Histogram to expect input:
function Histogram
What you need is something like this:
function Histogram(str)
% do something with str
I got this y'all!
Change your histogram function to this: (literally copy and paste what's below)
function Histogram(str) %Add input argument
%clear %DO NOT USE CLEAR in a function, the benefit of using a function is you don't have to %clear anything :)
clc;
fid = fopen(str); %Use input argument
myimage = fread(fid, [512, 683]); %take off *uint8
fclose(fid);
Read MATLAB's documentation, it is fantastic, and would allow you to see why fread and uint8 don't go together in a matter of seconds (seriously less than 20 seconds would give you your answer) and it would also solve all your other extremely basic issues you are having.