File Exchange

image thumbnail

Image Morphology

version 1.3.1.0 (462 KB) by Brett Shoelson
An interactive environment for morphologically operating on images.

66 Downloads

Updated 15 Nov 2019

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

The Image Morphology app is an interactive exploratory environment, with which you can try different morphological operations and structuring elements on your image.
This app supports most morphological operations, including those (like BWHITMISS) that can take multiple STRELS. All STRELS, including arbitrary ones, are now supported. You can easily see the effects of changing the size or shape of your STREL, or of trying different morphological operations. You can also "activate" the modified image to string operations.
The Image Morphology app is a REPLACEMENT FOR MORPHTOOL, which has been shared on the File Exchange since 2007. This version fixes several minor (but long-standing) bugs, and addresses changes needed for R2014b readiness. Image Morphology (as an app, or as function |imageMorphology|) should be more stable and less buggy than previous versions.

Comments/suggestions/collaborations welcome.

Cite As

Brett Shoelson (2019). Image Morphology (https://www.mathworks.com/matlabcentral/fileexchange/23697-image-morphology), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (66)

Misha

Hi Brett,
I'm still getting an error in R2019b with just downloaded (and installed) version:

Error:File: tabPanel.m Line: 317 Column: 10
Identifier 'tabCardPosn' is not a function or a shared variable. To share 'tabCardPosn' with nested function, initialize it in the current scope.

Any thoughts?
I tend to use this great tool all the time in older versions. Too bad that new version of MATLAB screwed up your code.

@Akhil and others:
I believe I have found and fixed the bug you've encountered. In R2019b, we changed the way that variables are shared between parent- and nested subfunctions; this caused an error in my code in a call to tabPanel. If you're interested:

https://www.mathworks.com/help/matlab/matlab_prog/upgrade-code-for-r2019b-changes-to-function-precedence-order.html

That said, it's a simple fix-- and I am posting new code forthwith.
Thanks for bringing this to my attention!
Brett

@Akhil, I would like to try to understand why you're getting that message, and how to fix it--but I am unable to reproduce it. Would you kindly email me directly at

char(cumsum([98 17 -11 7 -10 7 7 -4 -47 45 -12 19 -12 15 -8 3 -7 8 -69 53 12 -2]))

and provide reproduction steps, if possible. Also, what version of MATLAB are you using?
Thanks,
Brett

New to this and currently having this msg (" Activation-by-tab-handle not working! ") constantly displayed for every selection after fixing the message " Please define your arbitrary STREL, named "ArbStrel", in the Base Workspace." with " ArbStrel = strel('arbitrary',4); "

Please assist!

146/5000
Thank you very much for sharing. This application has been very useful to show my students of the vision course the concepts of morphology.

Sam Lim

iev6

Bro/Sis. You just saved my life.

@Hui:
The contrastEnhancement algorithm I implemented in imageMorphology was from "Digital Image Processing Using MATLAB," 2nd Edition, p. 529. It is fundamentally: Image + Tophat(Image) - Bothat(Image).

That said, it is a fairly generic contrast enhancer--one of several. (You might also consider imadjust(); )

Hui Huang

Hello, I am very interested in the code especially the part of contrast enhancement. And the contrast enhancement feature is very useful in my recent work. I want to know the details of this feature, can you please give me some reference papers or some suggestions? I will cite your work and your refence papers or books. You can also contact with me, the following is my e-mail address: huihuang_rs@163.com. Thank you very much.

How can I work with this morphtool ,give some guidance to me..

Leona Chan

@Siddhartha,
gobjects() was introduced in R2013a. You may be able to just replace that keyword with 'zeros' and make it work. (But you might also want to consider installing a newer version. There's a lot of new functionality, and there has been much work on improving the performance of MATLAB!)
Cheers,
Brett

Siddhartha

Dear Brett, I have got an error saying:

Undefined function 'gobjects' for input arguments of type 'double'.

Error in StrelTool (line 90)
shapePanel = gobjects(numel(strelShapes,1));

And I am using R2012a.

Liang Seacom

great help,thanks

@Chris,
Thanks very much for the note--always nice to hear that my software was helpful. I'd steer you to this blog post on the topic:
http://blogs.mathworks.com/community/2010/12/13/citing-file-exchange-submissions/

Cheers,
Brett

Dear Brett, your software helped me a lot and i would like to cite you on my work. could you please tell me how i can do that.

rabeeah

hi,
i am getting the following error when i run the tool:
??? Undefined function or method 'isgraphics' for
input arguments of type 'double'.

Error in ==> imageMorphology at 107
if isgraphics(imageMorphologyParent,'figure')

Excelente aplicación para la enseñanza de los conceptos de morfología básica.

Zafer

Bi

Bi

@Amarjot:
In R2009b, we allowed the use of a tilde to ignore unwanted function outputs:

[~,strelButtons,strelSliders] = StrelTool(strel1Parent);

If you're using an earlier version, you should 1) replace the tilde with a dummy variable (like "JUNK"); and 2) update your MATLAB!

Cheers,
Brett

Vinny

Brett, on an unrelated note
I tried contacting you but didnt get a reply. where can I find the demo files for your webinar on medical image processing ?

Amarjot

Hi,
??? Error: File: MorphTool.m Line: 218 Column: 3
Expression or statement is incorrect--possibly unbalanced (, {, or [. can you please help me correct itt

@Vinny:
narginck was added to MATLAB in R2011b. You can safely comment out that line, or replace it with:
nargchk(0,2,nargin)

(But you should upgrade! :) )
Cheers,
Brett

Vinny

im getting the following error (using matlab R2011a) :
"??? Undefined function or method 'narginchk' for input arguments of type 'double'.

Error in ==> MorphTool at 40
narginchk(0,2);"

@srinivasarao:
Sorry...not sure what paper you're talking about. This GUI agglomerates many of the morphological operations enabled through the Image Processing Toolbox, and allows interactive manipulation of all of their input parameters. There's no single paper to share.
Brett

hi Brett,
can u send me the base paper

I should clarify my previous comment. BWHITMISS does not _require_ two strels, but it does allow a 2-strel syntax.
Brett

Hi Anoosha,
Thanks for the rating! Some morphological operations (notably here, BWHITMISS) require the specification of two structuring elements. For the purposes of MorphTool, SE1 is read from StrelTool1, and SE2 is read from StrelTool2.
Cheers,
Brett

Hi Brett,
Could you please tell me what the difference between strelTool and strelTool2 is?

Caleb: I believe that the zip file creates a subdirectory that contains the helper files (including tabPanel). Please either drag them out of that folder, or add the folder to your MATLAB path and try again!

Caleb

I'm using R2011b and I'm getting "Undefined function 'tabPanel' for input arguments of type 'cell'.

Hi Bella,
Can you tell me how to recreate the error you're seeing? I never assigned a callback to a uipanel, nor have I seen that particular error. Is it reproducible? How can I trigger it (so I can figure out what's going on)? And what does "I have put the files outside the folder" mean? (I wonder if this is a path issue.)
Cheers,
Brett

Bella Sam

Hello, I am using 2009a, and i have put the files outside the folder..i have some problem and didn't know what these means::

??? Error using ==> get
There is no 'Callback' property in the 'uipanel' class.

Error in ==> iptaddcallback at 71
current_callback = get(h, callback);

Error in ==> MorphTool at 648
iptaddcallback(strelButtons(ii),'Callback',@morphOp);

Parth,
Can you give me some details about your MATLAB? Do you have the Image Processing Toolbox? What version of MATLAB are you using?
Thanks...Brett

Parth

hey there m gettin an error as this one:

??? Undefined command/function 'iptchecknargin'.

Error in ==> MorphTool at 24
iptchecknargin(0,2,nargin,mfilename);

recep

thanks alot it's work

recep, Kelly, et al: I see what's happening now. I provided auxiliary files in a folder, assuming that they would be put on your MATLAB path. You can either add those folders manually to the path, or drag the files out of the folders, or issue this (or equivalent) command:

addpath(genpath(fileparts(which('MorphTool.m'))))

Let me know if that addresses the issue, please.

@recep and Kelly: Would you please verify that you have the latest version, and that it came with the TabPanel function? If not, please grab the new version. If so, it would help if you could tell me reproduction steps that trigger the problem.
Thanks, Brett

recep

I use 2009a but I give problem like it:
??? Undefined function or method 'tabPanel' for input arguments of
type 'cell'.

Error in ==> MorphTool at 177
[mainTabHandle,tabCardHandles,tabHandles] = ...

Please try again; I believe that the current version includes all the files you need to run this. (Please let me know if there are any additional issues with MorphTool...).
Thanks, Bret

Kelly

Thanks Brett you are right I am using 2009a and the 'junk' insert fixed that error... however now I am getting a different error.

??? Undefined function or method 'tabPanel' for input arguments of type 'cell'.

Error in ==> MorphTool at 177
[mainTabHandle,tabCardHandles,tabHandles] = ...

@Kelly and YAZ (and others):

Thanks to you both. I just figured out that you are using a version of MATLAB that predates R2009b. (Correct?) I use tildes to ignore unwanted arguments; that capability was introduced in '9b.) TO FIX THIS: Either upgrade to a newer MATLAB ;), or replace the tildes in my code with some word like "junk." That should do it!

Kelly

I have the same error as YAZ
??? Error: File: MorphTool.m Line: 185 Column: 3
Expression or statement is incorrect--possibly unbalanced (, {, or [.

I did not backspace or delete anything and tried re-downloading it with the same error.

@YAZ
Is it possible that you accidentally backspaced and deleted something? I don't see any indication of an unbalanced parenthesis in that file. Would you re-download and verify the error, and let me know if you still see it, please?
Thanks,
Brett

YAZ

hi, i have this message :
"??? Error: File: MorphTool.m Line: 185 Column: 3
Expression or statement is incorrect--possibly unbalanced (, {, or [."

Bojan, Jonas: Should be good to go now...please re-try! Thanks for the heads up.

Give me a few minutes, Bojan and Jonas. I accidentally omitted that file when I updated. Working on it.

Jonas

Same error here as Bojan - StrelTool seems to be missing from the package, which makes the potentially awesome submission unusable.

Bojan

I'm having a problem running this as it requires StrelTool. Is StrelTool available on file exchange or part of another toolbox?

W

Great!Thanks!

@Nayanjyoti: You are correct: the file is 'cameraman.tif'; my code should reflect that. My windows machine has case-insensitive filename matching, which allowed me to be sloppy. Your Unix environment (correct?) is not. I'll modify the file.

Nayanjyoti

Hi Brett, I tried using a maci64 and glnxa64 and my experience was that when you do
>> I = imread('Cameraman.tif');

you get the following error
??? Error using ==> imread at 372
File "Cameraman.tif" does not exist.

whereas,
>> I = imread('cameraman.tif');
works fine.

@Nayanjyoti: Thanks for the feedback; I plan to continue ot expand MORPHTOOL. Actually, though (on a PC at least), imread is insensitive to the case of an input image name. So both "imread('Cameralman.tif')" and "imread('cameraman.tif')" work. (IMREAD calls FOPEN under the hood.) Do you see different behavior?

Nayanjyoti

In line 11
"imgName = 'Cameraman.tif';" needs to be replaced with
"imgName = 'cameraman.tif';"

Nayanjyoti

Simply mind-blowing. Would like to see it include more functionality.

Sami,
Thanks for the rating. I programmed the GUI manually, without the use of GUIDE. You don't need a .fig file to run it. Just issue the command 'morphtool' (or 'morphtool(myimage)') to run it.
Cheers,
Brett

Samiov

it looks great...but how make it works??? the .fig file isn't in the zipfile!! or I just must be inspired from the .m file???

important pour mon projet

Updates

1.3.1.0

V1.3.1.0 addresses a bug in tabPanel introduced by changes in the sharing of variables in subfunction workspaces.

1.3.0.0

Fixes an error that arose because of changes to core MATLAB's inclusion of subfunctions. Should be fine for R2019b and beyond. (Will work fine in earlier versions, too.)

1.2.0.0

A small bug fix in a portion of the generate code, plus better tooltips.

1.19.0.0

Users of MorphTool may want to consider upgrading to ImageMorphology. I addressed many small issues in this version.

1.18.0.0

Several improvements/updates, including better loading of new images (from file or workspace); default 0-sized strel (this is desirable for large images); and incorporation of new ExpandAxes, which now allows right-click exporting of images!

1.17.0.0

Added in sound files.

1.16.0.0

Updated to include an App file for R2012b.

1.14.0.0

Flattened directory structure to avoid confusion. Replaced deprecated argument-checking functions, and added file-loading functionality when MorphTool is a child of a figure.

1.13.0.0

Includes a missing subfunction.

1.12.0.0

Changed the description only.

1.11.0.0

Including omitted StrelTool file.

1.8.0.0

Updating screenshot.

1.5.0.0

Fixed stability/responsiveness issue. Also adds support for a number of different morphological operations.

1.3.0.0

09/09/2009 Provides missing functions/subfunctions.

1.1.0.0

9/5/2009 Re-zipped with missing functions StrelTool and expandAxes.

MATLAB Release Compatibility
Created with R2014b
Compatible with any release
Platform Compatibility
Windows macOS Linux