[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-patch-tracker] [patch #8812] Added imquantize to image toolset
From: |
anonymous |
Subject: |
[Octave-patch-tracker] [patch #8812] Added imquantize to image toolset |
Date: |
Fri, 27 Nov 2015 23:14:49 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36 |
URL:
<http://savannah.gnu.org/patch/?8812>
Summary: Added imquantize to image toolset
Project: GNU Octave
Submitted by: None
Submitted on: Fri 27 Nov 2015 11:14:48 PM UTC
Category: None
Priority: 5 - Normal
Status: None
Privacy: Public
Assigned to: None
Originator Email:
Open/Closed: Open
Discussion Lock: Any
_______________________________________________________
Details:
Attached is the diff patch,
following is the content of the m file submitted in the commit.
Please add it to the image toolset.
## Copyright (C) 2015 Motherboard
##
## This program is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn {Library Function} address@hidden = mat} imquant (@var{img}
mat, @var{levels} vector, @var{values} vector)
## quant_A = imquantize(A,levels) quantizes image A using specified
quantization values contained in the N element vector levels. Output image
quant_A is the same size as A and contains N + 1 discrete integer values in
the range 1 to N + 1 which are determined by the following criteria:
## If A(k) ≤ levels(1), then quant_A(k) = 1.
## If levels(m-1) < A(k) ≤ levels(m) , then quant_A(k) = m.
## If A(k) > levels(N), then quant_A(k) = N + 1.
## Note that imquantize assigns values to the two implicitly defined end
intervals:
## A(k) ≤ levels(1)
## A(k) > levels(N)
## example
## quant_A = imquantize(___,values) adds the N + 1 element vector values
where N = length(levels). Each of the N + 1 elements of values specify the
quantization value for one of the N + 1 discrete pixel values in quant_A.
## If A(k) ≤ levels(1), then quant_A(k) = values(1).
## If levels(m-1) < A(k) ≤ levels(m) , then quant_A(k) = values(m).
## If A(k) > levels(N), then quant_A(k) = values(N + 1).
## example
## [quant_A,index] = imquantize(___) returns an array index such that:
## quant_A = values(index)
## @seealso{}
## @end deftypefn
## Author: Motherboard <address@hidden>
## Created: 2015-11-27
function [quantImg, index] = imquantize (img, levels, values)
N = length(levels);
if ~exist("values","var")
values = 1:(N + 1); %if no values were given, set values to be labels.
valuesPresent = false;
elseif (length(values) ~= N + 1) %if values were given, make sure we have
exactly the right amount.
error("values should have length of levels + 1")
else
valuesPresent = true; %if values were given, and everything is fine, we
might need to calculate the output index.
endif
quantImg = zeros(size(img));
if isargout(2) %if index is required, initialize it.
index = quantImg;
endif
if (size(levels,1) == 1) %check if levels is a column or a row vector to
concatinate it correctly with 0 on one side, and 256 on the other.
levels = [0; levels; 256];
elseif (size(levels,2) == 1)
levels = [0 levels 256];
else
error("levels should be a vector") %make sure levels is a vector
endif
for i = 1:(N+1)
indicesToAssign = img >= levels(i) & img < levels(i+1); %compute the
indices to be assign.
quantImg(indicesToAssign) = values(i);
if (isargout(2) && valuesPresent) %if index is required, and values were
given, assign labels to index.
index(indicesToAssign) = i;
endif
end
if (isargout(2) && ~valuesPresent) %if index is required, but values were
not given, index is identical to quantImg
index = quantImg;
endif
endfunction
_______________________________________________________
File Attachments:
-------------------------------------------------------
Date: Fri 27 Nov 2015 11:14:48 PM UTC Name: imquantize.diff Size: 4kB By:
None
<http://savannah.gnu.org/patch/download.php?file_id=35581>
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/patch/?8812>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-patch-tracker] [patch #8812] Added imquantize to image toolset,
anonymous <=