You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
I am making a project on fingerprint verification in matlab in which I have made two files one is start file which is a script file (start.m) and another is a function file (fpmext.m) to verify minutiae details. Need to remove errors.
1 view (last 30 days)
Show older comments
I am making a project on fingerprint verification in MATLAB in which I have made two files: one is a start file which is a script file (start.m), and another is a function file (fpmext.m) to verify minutiae details. When I use the *.jpeg file the errors coming are:
Error in fpmext (line 10), binary_image=im2bw(imread(image));
Error in start (line 15), B=fpmext(Ieq2);
and when I use the *.tif file the errors are:
Error using histeq, Expected input number 1, I, to be two-dimensional.
Error in histeq (line 69), validateattributes(a,{'uint8','uint16','double','int16','single'},
Error in start (line 9), Ieq1=histeq(I1);imshow(Ieq1);
How do I get rid of all these errors?
Is there any procedure to link a function file with a script file or its enough that they are in one or same folder?
45 Comments
John D'Errico
on 24 Mar 2019
How to get rid of what seem to be distinct errors? You track down each problem and write code that will not cause that error.
No, you cannot "link" a particular separate function file with a script file.
As long as they are in the current working directory (thus what pwd tells you), the script can see all functions in that directory.
Or you can add a directory to your MATLAB search path. Then any function in that directory will be seen, by any function or script.
help addpath
help pathtool
N/A
on 24 Mar 2019
Thanks
What about the errors which I have written I dont understand what about how to remove these errors.
Walter Roberson
on 24 Mar 2019
We need to see the complete error messages.
The first error you show, at fpmext line 10, could occur if you did not pass in a file name to the function, or if the file is not found (such as if the file is in a different directory but you passed in only the basic file name without the folder information.)
N/A
on 26 Mar 2019
This time I have these logical errors in matlab built-in functions. No syntax errors. How to correct these logical errors.
Error using im2bw>parse_inputs (line 97)
IM2BW: Truecolor RGB image has to be an M-by-N-by-3 array.
Error in im2bw (line 38)
[A,map,level] = parse_inputs(varargin{:});
Error in start (line 12)
binary_imagefp4=im2bw(imread('fp4.tif'));
Walter Roberson
on 26 Mar 2019
Assign the results of the imread to a variable and then look at size of the variable. I suspect that you might be dealing with an RGBA or cmyk tif.
N/A
on 26 Mar 2019
size is:
ans =
1300 1140 4
Do I need to convert it to size of m x n x 3 to remove error? If so then how?
Do I need to convert image into grayscale in order to have maximum information?
Walter Roberson
on 26 Mar 2019
What shows up for
imfinfo('fp4.tif')
Probably you can use
temp = imreadd('fp4.tif');
binary_imagefp4 = im2bw(temp(:,:,1:3));
but I will need to see the imfinfo output to be sure.
N/A
on 26 Mar 2019
imfinfo shows:
Filename: 'D:\IU\DIP\project\fp4.tif'
FileModDate: '23-Mar-2019 12:03:33'
FileSize: 1277988
Format: 'tif'
FormatVersion: []
Width: 1140
Height: 1300
BitDepth: 32
ColorType: 'truecolor'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubFileType: 0
BitsPerSample: [8 8 8 8]
Compression: 'LZW'
PhotometricInterpretation: 'RGB'
StripOffsets: 8
SamplesPerPixel: 4
RowsPerStrip: 1300
StripByteCounts: 1277617
XResolution: 299.9990
YResolution: 299.9990
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: [255 255 255 255]
MinSampleValue: [0 0 0 0]
Thresholding: 1
Offset: 1277626
Predictor: 'Horizontal differencing'
ExtraSamples: 2
UnknownTags: [1x1 struct]
With (:,:,1:3) following errors are coming:
Error using rgb2gray>parse_inputs (line 82)
MAP must be a m x 3 array.
N/A
on 26 Mar 2019
Now I have just one error shown below the rest looks fine.
Index exceeds matrix dimensions.
Error in start (line 25)
binary_imagefp2 = binary_imagefp2(120:400,20:250);
Walter Roberson
on 26 Mar 2019
I confirm from that imfinfo output that what you have is RGBA . indexing at (:,:,1:3) should work.
Walter Roberson
on 26 Mar 2019
We do not know how binary_imagefp2 was created, so we do not know what size it is.
N/A
on 26 Mar 2019
I have created four of this type and in only one the above error is coming.
im2=imread('fp2.tif');
binary_imagefp2=im2bw(im2(:,:,1:3));
binary_imagefp2 = binary_imagefp2(120:400,20:250);
Remaining three are exactly the same and they are not showing any error.
N/A
on 26 Mar 2019
After this I need to take input of a fingerprint picture from the user to match with the existing pictures, I know GUIDE only for this purpose but its very difficult. How to browse the desired image and then place it in the script file.
Walter Roberson
on 26 Mar 2019
[filename, filedir] = uigetfile({'*.jpg'; '*.jpeg'; '*.bmp'; '*.png'; '*.tif'}, 'Pick a file');
if isnumeric(filename); return; end %user cancelled
fullname = fullfile(filedir, filename);
im2 = imread(fullname);
if ndims(im2) > 1
im2 = im2(:,:,1:3); %rgba -> rgb
end
binary_imagefp2 = im2bw(im2);
N/A
on 27 Mar 2019
Thanks a lot!
I have five fingerprint images:
When I select first fingerprint image the program is giving proper output.
When I select second fingerprint image following error comes:
Index exceeds matrix dimensions.
Error in start (line 26)
binary_imagefp4 = binary_imagefp4(120:400,20:250);
When I select third fingerprint image following error comes:
Index exceeds matrix dimensions.
Error in start (line 17)
im4 = im4(:,:,1:3); %rgba -> rgb
When I select fourth fingerprint image following error comes:
Error using imread (line 349)
File "fp0.tif" does not exist.
Error in start (line 15)
im4 = imread(fullname);
When I select fifth fingerprint image following error comes:
Error using imread (line 349)
File "fp5.jpg" does not exist.
Error in start (line 15)
im4 = imread(fullname);
All the images are of RGB format I have checked their details in properties.
Walter Roberson
on 27 Mar 2019
[filename, filedir] = uigetfile({'*.jpg'; '*.jpeg'; '*.bmp'; '*.png'; '*.tif'}, 'Pick a file');
if isnumeric(filename); return; end %user cancelled
fullname = fullfile(filedir, filename);
if ~exist(fullname, 'file')
error('somehow the file whose name we just fetched does not exist??: "%s"', fullname);
end
im2 = imread(fullname);
if ndims(im2) > 3
fprintf(2, 'Warning: ignoring all except first image in file "%s"\nOriginal is size ', filename);
disp(size(im2));
im2 = im2(:,:,:,1); %image stack or animated gif
end
if ndims(im2) > 2
if size(im2,3) < 3
fprintf(2, 'Warning: ignoring alpha as second pane in file "%s"\n', filename);
im2 = im2(:,:,1); %grayscale tif with unassociated alpha
elseif size(im2,3) > 3
fprintf(2, 'Warning: ignoring extra panes such as alpha in file "%s"\nOriginal is size ', filename);
disp(size(im2))
im2 = im2(:,:,1:3); %rgba -> rgb
end
end
if size(im2,1) < 400 || size(im2,2) < 250
error('file "%s" does not have at least 400 rows or 250 columns, is only %d x %d', fullname, size(im2,1), size(im2,2));
end
binary_imagefp2 = im2bw(im2);
Walter Roberson
on 27 Mar 2019
Are you sure you got the file names through the uigetfile() + fullfile() code path? uigetfile is defined to return the full directory name as the second output, even if the user happens to select from the current directory, and once that full directory name is added to the file name by using fullpath, it should not be possible for a filename without directory to be passed to imread() in my code. When imread() cannot find the file, it always reports the complete path that was passed in, including any directory. Notice in each case the error message you report only has the bare file name with no directory, which is not the form that imread() would output if imread() had been passed the complete file name.
My suspicion is that you did not use the fullfile() step to add the directory of the file to the file name.
N/A
on 29 Mar 2019
I have used uigetfile() to select which file to choose for matching and it has no errors. I removed fullfile(), which makes no difference. The errors coming after removing the fullfile() are my defined except one which is:
Index exceeds matrix dimensions.
Error in start (line 60)
binary_imagefp1 = binary_imagefp1(120:400,20:250);
Why every image is not giving output irrespective of their dimensions or type? How to remove or deal with this dimensions problem? In the program I have applied checks on *.tif files to get the output. In properties > details of the *.tif file its written photometric interpretation RGB now that makes it enough to give the desired output. Do I need to convert to gray scale then the program does not give errors? What type of images to use in this program so that I do not get all types of error messages?
Walter Roberson
on 29 Mar 2019
What happened when you used the code I posted in https://www.mathworks.com/matlabcentral/answers/452018-i-am-making-a-project-on-fingerprint-verification-in-matlab-in-which-i-have-made-two-files-one-is-st#comment_686745 ?
That code already converts grayscale, and grayscale+alpha, and RGB and RGB+alpha to black and white.
N/A
on 30 Mar 2019
I have used your given code, removed fullfile() as you were getting suspicious about it and instead of using fullname I have used filename to get output. On one file the program is giving the error which I have mentioned in my last posting related to index exceeding matrix dimensions. The rest four are our defined errors and not even a single output. Previously it was showing one output on fp1 now on selecting fp1 it is showing error which I have mentioned in my last posting related to index exceeding matrix dimensions.
If I comment the line:
binary_imagefp2 = binary_imagefp2(120:400,20:250); %This is for image file# 2 not of user selected file
its giving proper output on fp1, our defined error on fp2, output on fp3 but only one thinned image is missing of fp3 the code is:
figure;subplot(121);imshow(thin_imagefp4);subplot(121);imshow(thin_imagefp3);suptitle('Thinned Image of fingerprint 3 and 4');
On the images fp0 and fp5 the program is giving our defined errors which I have put in a folder within our project folder.
Image Analyst
on 30 Mar 2019
Why won't you let us run it? Why won't you attach your script and image(s) so we can try it ourselves? It looks like you have not read this link yet.
Walter Roberson
on 30 Mar 2019
My suspicion was that you had removed the fullfile when you should not have.
N/A
on 31 Mar 2019
I have the attatched the zip file of my project. Please do not make unnecessary changes only do what is necessary to run the code.
Walter Roberson
on 31 Mar 2019
Well you should not have commented out the fullfile(), and you should have used fullname instead of filename consistently after the fullname() call. But that would only affect trying to work with files that were not in your current directory.
Other than that everything looked fine to me. You got the intended warnings for when you read in RGBA images, and the RGBA images were properly converted to RGB images and those were properly converted to black and white. That all looked fine.
The code also properly rejected the images such as fp2.jpg that are too small for your algorithm to process. The code did not end up with any messages about subscript out of range: it smoothly gave messages about the file not having enough rows or columns, listing the sizes required and saying what size it was instead of the size needed. This is what the code should do (unless you want to redesign it to pop up a warning window instead of giving an error condition.)
Now, you know of course that your algorithm is broken for any fingerprints that are not very close to the particular size you expect, or that are not in the orientation you expect -- but that is a different topic. Expecting your interesting content to always be in row 120 to 400 and columns 20 to 250 was always going to be problematic. Imagine for example that you got a fingerprint with a 10 times resolution, where the interesting content was rows 1200 to 4000: your code would look in the wrong place.
But meanwhile the code is already fine at converting images and rejecting images that are too small for your specialized algorithm. Well, other than that you really should be using fullfile()...
Walter Roberson
on 2 Apr 2019
Are you continuing to get errors on images other than the message I put in about the input image being too small and what size it needed and what size it really was? If you are getting messages about subscript out of range or about im2bw failing, then I will need copies of those image files to test with.
If the issue is just the message about the image being too small, then that is an issue for you to solve. What did you intend by accessing those particular rows and columns of the image? What were you looking for there? What are some characteristics of that section that might permit you to recognize that section in other images of different sizes or with different margins?
N/A
on 4 Apr 2019
I took three images from google to check the output messages. The messages you put in about the input image being too small and what size it needed and what size it really was are coming. No messages about subscript out of range or about im2bw failing. I intend to check whether the selected image matches with the images we already have irrespective of their sizes. Matlab checks that two images are matching or not piece by piece or matrix by matrix and then give the result as true or false that’s what I want to do.
Walter Roberson
on 4 Apr 2019
You need to figure out which part of the fingerprint image matrix you want to extract, then you need to extract it, and then you need to imresize() it to a consistent size.
The difficult part is in figuring out which part of the fingerprint image matrix you want to extract. You have given us no information as to what was important about the region 120:400, 20:250 when you were testing before. Like why wasn't it 1:400, 1:200 ? What was in the 1:119 that you wanted to ignore? What was in the 200:250 that you wanted to keep? What was in the 251:end that you wanted to ignore?
Walter Roberson
on 5 Apr 2019
code + image was attached at one point, and I could post those images. But posting those would not tell me the reasoning for having selected those particular sections of the images.
Image Analyst
on 5 Apr 2019
But if he ever does explain your question, it would help to have the image attached to see what he's talking about I looked over all the past comments and didn't see the image attached anywhere.
N/A
on 5 Apr 2019
Edited: N/A
on 5 Apr 2019
I have taken all these images from google search.
By using imresize(image file name,1.75) the program is giving output but it’s not proper and the images displayed in the output are not fine. Now how to trace and correct this problem? Need to enhance the image also after resizing or what and then by which function to enhance the image?
I have kept two images in a sub folder of the program folder which is not getting fetched and giving error defined in the program.
Somehow the file whose name we just fetched does not exist??: "D:\IU\DIP\project\New folder\fp5.jpg"
Image Analyst
on 5 Apr 2019
I'm not sure what your recent edit was, but evidently it was not to attach start.m and fpmext.m.
To get files in subfolders you have to use two stars in your file pattern to dir() or else you have to use fileDatastore().
Walter Roberson
on 5 Apr 2019
Do not imresize() a file name. You imresize() what you get from imread() .
I would suggest that you only work with images which do not have text labels like the "shutterstock" on them.
I suggest that you imread() the file, and im2bw() that. Then, take the negation of it so that all the black pixels become high value and all of the white pixels become 0. regionprops to detect the orientation. Rotate the image around its centroid to make the major axes vertical; https://www.mathworks.com/matlabcentral/fileexchange/40469-rotate-an-image-around-a-point . regionprops() to detect the bounding box of the rotated image and extract that. Now imresize() to a fixed size and proceed to do feature analysis.
N/A
on 6 Apr 2019
There is just one script file start.m which I am going to attach. Right now attachment button is not working.
Do I need to do the following with every image?
A=imread('112.png');
B=im2bw(A);
im4=imcomplement(B);
rp1=regionprops(im4,'BoundingBox','MajorAxisLength','MinorAxisLength');
D=imrotate(im4,90);
rp2 = regionprops(D, 'BoundingBox','MajorAxisLength','MinorAxisLength');
figure;imshow(D);
hold on;
%R=rectangle('Position', rp2.BoundingBox,'EdgeColor','b');
croppedImage2 = imcrop(rp2, rp2.BoundingBox);%Extract image from the region props
%figure;imshow(croppedImage2);
C=imresize(croppedImage2,2);
What is the use of taking negation or complement of the original image? It’s of no use. Why to region props the negated image? rp1 is also of no use.
After rotation if we are doing region props then its looks fine.
How to remove following error?
Error using imcrop>parseInputs (line 196)
Too many input arguments.
Error in imcrop (line 93)
[x,y,a,cm,spatial_rect,h_image,placement_cancelled] = parseInputs(varargin{:});
Error in Untitled (line 11)
croppedImage2 = imcrop(rp2, rp2.BoundingBox);%Extract image from the region props
Walter Roberson
on 6 Apr 2019
The information you need is in the black pixels. regionprops ignores black pixels thinking that they are background.
N/A
on 7 Apr 2019
Inorder to access the folder also I need to use fileDatastore() instead of uigetfile()???
With *.jpg, *.png the program is giving output, with .tif its giving error. *.tif file cannot be attached over here. How to make it a separate function and call it where required in start.m script file. Following is the code:
A=imread('112.jpg');
B=im2bw(A);
im4b=imcomplement(B);
rp1=regionprops(im4b,'BoundingBox','MajorAxisLength','MinorAxisLength');
D=imrotate(im4b,90);
rp2 = regionprops(D, 'BoundingBox','MajorAxisLength','MinorAxisLength');
figure;imshow(D);
hold on;
croppedImage2 = imcrop(rp2.BoundingBox);%Extract image from the region props
C=imresize(croppedImage2,2);%are we going to match this image with others in our record????
figure;imshow(C);
How to correct the following error in imresize()?
Error using imresize
Expected input number 1, A, to be nonempty.
Error in imresize>parsePreMethodArgs (line 333)
validateattributes(A, {'numeric', 'logical'}, {'nonsparse', 'nonempty'}, mfilename, 'A', 1);
Error in imresize>parseInputs (line 248)
[params.A, params.map, params.scale, params.output_size] = ...
Error in imresize (line 141)
params = parseInputs(varargin{:});
Error in Untitled (line 12)
C=imresize(croppedImage2,2);%are we going to match this image????
Image Analyst
on 7 Apr 2019
You need to pass the image into imcrop, not just the bounding box. Otherwise how could it possibly know which of the many image variables you want to crop? You have
croppedImage2 = imcrop(rp2.BoundingBox);%Extract image from the region props
but rp2 is the bounding box. Where is the first argument to imcrop, the image? You can't crop a list of 4 numbers, which is what rp2.BoundingBox is. You have many images there (most of which have poorly chosen names) like A, B, im4b, D, croppedImage2, C, etc. Whichever one of those you want to crop, pass that in to imcrop().
Walter Roberson
on 7 Apr 2019
It is not clear to me what additional information you expect to be able to get from bounding box and major and minor axis length of the same image rotated by 90 degrees?
I wonder if you misunderstood what I was saying about rotating the image? I did not say to rotate it by 90 degrees: I said to find the orientation (of the whole fingerprint) and rotate the image so that the whole fingerprint is vertical or horizontal.The angle to rotate would be found by calculating based upon the orientation property returned by regionprops.
I would suggest that at this stage you do not want to get the boundaries of each individual blob within the fingerprint image. I think at this stage you just want to know where the edges of the whole fingerprint image are so you can get rid of any useless white border around it.
One hint: if you have a binary image and you want regionprops to give you information about the whole image instead of about each individual part of the image, then ask regionprops to work on double() of the binary image. The double() will indicate to regionprops that you want it treated as a "label image".
Image Analyst
on 7 Apr 2019
You can also use the radon transform to determine the rotation angle, as my attached demo shows.
N/A
on 22 Apr 2019
When if select the image file fp1 the program start.m is giving proper output, when I select the image file fp2 the program is matching with fp1 instead of fp2, image file fp3 is getting matched with fp4 instead of fp3, image file fp4 is not getting matched with any in our record it should match fp4, image file fp5 is getting matched with fp1 instead of fp5. How to correct all these errors in the output in our program?
Walter Roberson
on 22 Apr 2019
We do not know what your current code is.
Note: neither Image Analyst nor I have studied fingerprint analysis techniques. I do not intend to study those techniques, so I will not be offering algorithms assistance on the topic.... only assistance on matters such as how to put all the bounding boxes from regionprops into a single array.
Accepted Answer
Image Analyst
on 24 Mar 2019
Edited: Image Analyst
on 24 Mar 2019
These might be caused by your images being color instead of gray scale. Look into rgb2gray().
Also, don't use image as the name of your variable since that's the name of a built in function.
1 Comment
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)