How to convert stance image from index to grayscale
Afficher commentaires plus anciens
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;
end
Réponses (3)
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)
imshow(ypict)
John BG
le 17 Mar 2016
Hi Denni
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')
imshow(A)

1.-
A1=A(:,:,1);A2=A(:,:,2);A3=A(:,:,3)
Y_CCIR601=.299*A1+.587*A2+.114*A3
imwrite(Y_CCIR601,'Y_CCIR601.png') % save BW image in graphics file format

2.-
Y_ITUR=.2126*A1+.7152*A2+.0722*A3
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
John
Image Analyst
le 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);
end
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));
end
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.
6 commentaires
Denni Purcell
le 17 Mar 2016
Image Analyst
le 17 Mar 2016
Sorry - my typo. According to your original code, your variable was called map1 instead of map, so change it to map1 and it should work.
Denni Purcell
le 21 Mar 2016
Image Analyst
le 21 Mar 2016
This was your code:
I = ind2gray(thisPhase,map1);
so where did you get map1???? I have no idea because you did not show me that code. It would have to be something or else you couldn't even do what you showed, even if you did have the toolbox. So show the code from that program where map1 was first assigned.
Denni Purcell
le 21 Mar 2016
Image Analyst
le 21 Mar 2016
I have no idea where they got map1. It should have thrown an error since it's not defined before they started using it.
Catégories
En savoir plus sur Code Performance dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
