You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Error with function duplicate name where there is only one function.
1 view (last 30 days)
Show older comments
Hello
Matlab tries to call a function with the name "SegmentBone" as you can see from the example but I get the error of duplicate name and that Matlab cannot define it. There is only one SegmentBone.m in the folder. Why duplicate name?
Error: File: SegmentBone.m Line: 7 Column: 18
Function with duplicate name "SegmentBone" cannot be defined.
Error in Test1 (line 38)
imSeg = SegmentBone(im, 10e6, 0.031);
9 Comments
Adam Danz
on 18 Jun 2019
Make sure your main function name matches the m file name and that you don't have two different functions with the same name within the file. This demo below reproduces your error (saved in a file name SegmentBone.m).
function y= SegmentBone(x)
q = jff(4);
y = x * q;
function q = SegmentBone(x)
q = x+1;
y = SegmentBone(1);
Error: File: SegmentBone.m Line: 7 Column: 14
Function with duplicate name "SegmentBone" cannot be defined.
Stelios Fanourakis
on 18 Jun 2019
I use that code. There is no SegmentBone.m in the same script anywhere else or in the working folder.
% Apply the bone segmentation to test image and show the results
clc
close all
clear all
path = imread('2A.bmp');
imROIminX = 159;
imROImaxX = 536;
imROIminY = 33;
imROImaxY = 410;
% path = 'Z:\Data\Cadaver_Experiment_2\Data\MaleCadaver\1\center\im';
% imROIminX = 159;
% imROImaxX = 536;
% imROIminY = 33;
% imROImaxY = 410;
i = 69; %81;
lp = sprintf('%s%04d.bmp', path, i);
im = imread('2A.bmp');
%%
%
% for x = 1:10
%
% for x = 1:10
% disp(x)
% end
%
% disp(x)
% end
%
im = im(imROIminY:imROImaxY, imROIminX:imROImaxX);
im = im2double(im);
[imH, imW] = size(im);
% im = flipdim(im,2);
figure, imshow(im);
tic
imSeg = SegmentBone(im, 10e6, 0.031);
toc
% figure, imshow(imSeg)
im4 = imresize(im,size(imSeg));
% subplot(1,2,1), imshow(im4)
% subplot(1,2,2), imshow(imSeg)
[BoneIdx] = find(imSeg>0);
imOverlapped = im4;
imOverlapped(BoneIdx) = 1;
figure, imshow(imOverlapped)
% imwrite(im4,'results\5_original.bmp','bmp');
% imwrite(imOverlapped,'results\T9SegIM.bmp','bmp');
Stelios Fanourakis
on 18 Jun 2019
Edited: Stelios Fanourakis
on 18 Jun 2019
1) Yes it's the correct function
This is the SegmentBone.m function. It starts at line 7 where all the previous lines are comments in green
function imSeg = SegmentBone(USimage, USfreq, USdepth)
[imH, imW] = size(USimage);
% calculate the segmentation parameters from US image parameters
boneTh = 1/8; % used for masking
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Downsampling
DownSampleFactor = 4;
% filter
Gsigma = 6;
hsize = floor(Gsigma*3)*2+1;
h = fspecial('gaussian', hsize, Gsigma);
imBlured = imfilter(USimage, h, 'replicate', 'same');
imBlured = imBlured(1:DownSampleFactor:imH,1:DownSampleFactor:imW);
imBlured = AdjustContrast(imBlured);
figure, imshow(imBlured)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h = [0 -1 0; -1 4 -1; 0 -1 0];
imBLOG = imfilter(imBlured, h, 'replicate', 'same');
imBLOG = (imBLOG>0).*imBLOG;
imBLOG = imBLOG/max(imBLOG(:));
figure, imshow(imBLOG)
% To make the algorithm faster, keep track of the points that are probable
% to be the bone surface
% First: Apply the threshold to the image (this is a loose threshold)
imMask = (imBlured >= boneTh);
[imH, imW] = size(imMask);
BorderRigeon = round((0.002/USdepth)*imH);
imMask(1:BorderRigeon,:) = 0;
% calculate the weight for underneath shadowness
Wshw = CalcBoneShadow(imMask, imBlured);
figure, imshow(Wshw);
% calculate the intensity weight
Wint = imMask .* (imBlured+imBLOG);
Wint = AdjustContrast(Wint);
figure, imshow(Wint);
% calculate the total Boniness, (Multipication prefered over addition)
Bness = Wshw.*Wint;
Bness = Bness/max(Bness(:)); % normalize
figure, imshow(Bness);
% imwrite(Bness, 'results\cadaver_2_50_Bness.bmp', 'bmp');
% Find bone surface using Dynamic Programming
% Smoothness will be applied through DP
% Presence of bone will be also determined using DP
% imSeg = FindBoneDP(Bness);
F0 = 50.0; F1 = 100.0; Bth = 0.55; % bone threshold between 0 and 1
JumpConst = 1.5;
% imSeg = FindBoneDP(Bness,F0,F1,Bth,JumpConst);
imSeg = SegmentBoneDP(Bness,F0,F1,Bth,JumpConst);
end
Adam Danz
on 18 Jun 2019
Edited: Adam Danz
on 18 Jun 2019
My first "quick thing" doesn't address whether you're using the correct function. It confirms that there are no other files with the same name. Did you run that line? What does it output?
which SegmentBone -all
Also, what version of matlab are you using? If there are any non-comments prior to the first line of code where the function is declared, that would produce the error you're getting (in r2016a or prior).
Stelios Fanourakis
on 18 Jun 2019
No, there is only one segmentBone.m function using the which command
I use R2018b
Adam Danz
on 18 Jun 2019
If you attach SegmentBone.m, Test1.m, 2A.bmp, and any other inputs needed to recreate the problem, I can look into it further.
Stelios Fanourakis
on 18 Jun 2019
I use the line
mex SegmentBone.cpp
This should do the compiling from cpp to Mex. However, I get the error
mex SegmentBoneDP.cpp
Building with 'Xcode Clang++'.
Error using mex
/Users/steliosphanourakes/Desktop/Matlab/DesMoines/karadokei -
Copy/FANOURAKIS_STELIOS12/20190516144930/SegmentBoneDP.cpp:17:17: error: assigning to 'const int *' from
incompatible type 'const mwSize *' (aka 'const unsigned long *')
DimsBness = mxGetDimensions(prhs[0]);
^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018b.app/extern/include/matrix.h:243:25: note: expanded from macro 'mxGetDimensions'
#define mxGetDimensions mxGetDimensions_730
^
/Users/steliosphanourakes/Desktop/Matlab/DesMoines/karadokei -
Copy/FANOURAKIS_STELIOS12/20190516144930/SegmentBoneDP.cpp:30:15: error: no matching function for call to
'mxCreateNumericArray_730'
plhs[0] = mxCreateNumericArray(2,DimsBness,mxDOUBLE_CLASS,mxREAL);
^~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018b.app/extern/include/matrix.h:275:30: note: expanded from macro 'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018b.app/extern/include/matrix.h:1247:1: note: candidate function not viable: no known
conversion from 'const int *' to 'const mwSize *' (aka 'const unsigned long *') for 2nd argument
mxCreateNumericArray(mwSize ndim, const mwSize *dims, mxClassID classid, mxComplexity flag);
^
/Applications/MATLAB_R2018b.app/extern/include/matrix.h:275:30: note: expanded from macro 'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^
2 errors generated.
Anyone who can responsibly help me?
Thanks
Walter Roberson
on 18 Jun 2019
You duplicated that into another question. The volunteers are not fond of answering the same query in three different Questions.
Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
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 (한국어)