How to convert stance image from index to grayscale
3 visualizzazioni (ultimi 30 giorni)
I am looking to replace the 'ind2gray' function as we no longer have access to the image processing toolbox. Is there a script to replace it?
% Convert stance image for each phase from 'index' to 'grayscale' and
% insert into Phases field: ManipulatedStances
for k = 1 : numPhases;
thisPhase = (Phases(k).Stance);
I = ind2gray(thisPhase,map1);
Phases(k).ManipulatedStances = I;
DGM il 12 Set 2023
Modificato: DGM il 12 Set 2023
No, don't use BT709 luma.
No, don't discard columns from the colormap.
If you're using IPT ind2gray(), just use ind2rgb(). It's not part of IPT, nor was it in IPT in 2016.
% get an indexed color image
[indpict CT] = imread('canoe.tif');
% convert to RGB
rgbpict = ind2rgb(indpict,CT);
% calculate luma
% since we don't have IPT, and we're living in early 2016, do it manually
factors = permute([0.299 0.587 0.114],[1 3 2]); % Rec 470/601 (this is what ind2gray would use)
ypict = sum(bsxfun(@times,im2double(rgbpict),factors),3);
ypict = im2uint8(ypict); % assuming you want uint8 output
% is there a difference? no, not really.
ypict0 = ind2gray(indpict,CT); % for comparison
immse(ypict0,ypict) % nothing but rounding errors (1LSB in a few specks)
John BG il 17 Mar 2016
You want to go from RGB to Y. Y is called luminance.
There is a good presentation of TV colour calibration charts in
Basically, there are 2 industry accepted standards to calculate Y from RGB:
A=imread('PAL TV colour calibration chart 1.jpg')
imwrite(Y_CCIR601,'Y_CCIR601.png') % save BW image in graphics file format
imwrite(Y_ITUR,'Y_ITUR.png') % save BW image in graphics file format
If you find this answer of any help solving your question, please click on the thumbs-up vote link,
thanks in advance
Image Analyst il 17 Mar 2016
If you have a map, that converts indexed into gray, you can do it with a for loop. If the map is a 256 by 3, then extract just the first column so it's a 1-D vector of 256 elements.
if size(map, 2) > 1
map = map(:, 1);
Since you don't have intlut() either (because you no longer have the toolbox), you'll have to use a for loop
grayImage = zeros(size(thisPhase)); % Initialize
for k = 1 : numel(grayImage)
inputIndex = thisPhase(k);
grayImage(k) = uint8(255 * map(inputIndex));
Now grayImage will be a uint8 2D array the same size as thisPhase with gray levels in the range 0-255 that were assigned according to the map that you appear to have already.