[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ind2rgb - Enabling handling of ND images
From: |
Jordi Gutiérrez Hermoso |
Subject: |
Re: ind2rgb - Enabling handling of ND images |
Date: |
Wed, 3 Apr 2013 16:54:11 -0400 |
On 3 April 2013 05:14, adam aitkenhead <address@hidden>
wrote:
> Currently ind2rgb can only handle 2D images. It'd be useful if it
> could handle ND images (3D and 4D images are quite common in medical
> applications), so I've attached a patch which enables this. The
> changes I've made are to ind2rgb.m and ind2x.m.
>
> This will bring ind2rgb more into line with Matlab's behaviour, as
> it can also handle ND images. In fact, Matlab's ind2rgb (for R2010a
> anyway, I don't know about later versions) only allows ND images to
> be handled if called with three outputs:
>
> [R,G,B] = ind2rgb(image,colormap);
>
> ...but I don't see any reason why it shouldn't also work with a
> single output:
>
> [R] = ind2rgb(image,colormap);
>
> ...so the attached patch works for ND arrays for both 1 and 3
> outputs.
The patch looks good. I am only bothered by minor stylistic issues.
1) It needs a commit message:
http://wiki.octave.org/Commit_message_guidelines
Look at "hg log -v" to look at other examples of commit
messages.
2) The traditional variable name is "sz = size (x)", not "xdim".
3) Instead of
R = vertcat (R(:), G(:), B(:));
R = reshape (R, horzcat (xdim, 3));
I would write
R = reshape ([R(:); G(:); B(:)], [sz, 3]);
or even, to be visually suggestive,
R = reshape ([R(:)
G(:)
B(:)], [sz, 3]);
I just find that using [a; b] or [a, b] is easier to read than
horzcat or vertcat. If you think my version is less readable,
keep yours.
If you can prepare a modified patch, please upload it to our patch
tracker:
https://savannah.gnu.org/patch/?func=additem&group=octave
If you're currently standing on your patch (hg up -r 486ebe96d), you
may want to use, after making your changes, the following:
hg commit --amend
to amend your current patch.
Looking forward to your contribution,
- Jordi G. H.