Code covered by the BSD License  

Highlights from
N-dimensional find

5.0

5.0 | 1 rating Rate this file 5 Downloads (last 30 days) File Size: 1.84 KB File ID: #27755
image thumbnail

N-dimensional find

by Sven

 

26 May 2010 (Updated 11 Oct 2011)

FIND_NDIM Finds the first or last nonzero element indices along a given matrix dimension.

| Watch this File

File Information
Description

This function finds the 'first' pixel in an image along a dimension. This is somewhat like measuring from the top row of an image towards the bottom row of the image, and recording the first collision with an "on" pixel.

%FIND_NDIM Finds first/last nonzero element indices along a dimension.
% I = FIND_NDIM(BW,DIM) returns the subscripts of the first nonzero elements
% of BW along the dimension DIM. Output I will contain zeros in element
% locations where no nonzero elements were found
%
% I = FIND_NDIM(BW,DIM,'first) is the same as I = FIND_NDIM(BW,DIM).
%
% I = FIND_NDIM(BW,DIM,'last') returns the subscripts of the last nonzero elements
% of BW along the dimension DIM.
%
% Example 1:
% If X = [0 1 0
% 1 1 0]
%
% then find_ndim(X,1) is [2 1 0] and find_ndim(X,2) is [2
% 1];
% Example 2:
% I = imread('rice.png');
% greyIm = imadjust(I - imopen(I,strel('disk',15)));
% BW = imclearborder(bwareaopen(im2bw(greyIm, graythresh(greyIm)), 50));
% topMostOnInds = find_ndim(BW, 1, 'first');
% rightMostOnInds = find_ndim(BW, 2, 'last');
% figure, imshow(BW), hold on
% plot(1:size(BW,2), topMostOnInds, 'r.')
% plot(rightMostOnInds, 1:size(BW,1), '.b')

A discussion of how this came about is at:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/244823

MATLAB release MATLAB 7.10 (2010a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
12 Oct 2011 Joachim  
Please login to add a comment or rating.
Updates
11 Oct 2011

Updated icon and help

Tag Activity for this File
Tag Applied By Date/Time
find Sven 27 May 2010 11:41:40

Contact us at files@mathworks.com