how to get rgb from this tiff image file?
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a .tif file I'm trying to open as a RGB. It can be downloaded here: https://files.fm/u/gssafxb9#_
It has 4 channels. I tried the following but did not work:
Itrain = double(imread('zh12.tif'));
% Extract the individual red, green, and blue color channels.
redChannel = Itrain(:, :, 1);
greenChannel = Itrain(:, :, 2);
blueChannel = Itrain(:, :, 3);
% Channel = Itrain(:, :, 4);
% % Recombine separate color channels into an RGB image.
Itrain = uint8(cat(3,redChannel, greenChannel, blueChannel ));
figure;
subplot(1,2,1); imagesc(Itrain); title('image')
any help to get the image opened as an RGB is appreciated.
0 Kommentare
Antworten (3)
Walter Roberson
am 25 Jun. 2017
Bearbeitet: Walter Roberson
am 25 Jun. 2017
Itrain = imread('zh12.tif');
channel4 = Itrain(:,:,4);
Itrain = Itrain(:,:, 1:3);
scaled_train = mat2gray(Itrain);
image(scaled_train);
Note: imagesc() effectively does not scale RGB images; mat2gray() works though.
3 Kommentare
Walter Roberson
am 25 Jun. 2017
Ummm,... No?
There is nothing obvious in the metadata of the .tif that would allow it to be presented that brightly.
You can use geotiffinfo() and geotiffread() but those do not seem to give any hints about the coloring.
I might be able to work out a correspondence, possibly. It appears it will not be straight-forward.
Walter Roberson
am 25 Jun. 2017
Bearbeitet: Walter Roberson
am 25 Jun. 2017
Suppose we operate under the assumption that each color plane in the desired image is a linear combination of the four planes of the original image. The original is uint16 and the target is uint8 but that does not matter for this purpose: it just implies that there will be scaling factors with absolute value less than 1.
Given two images the same size but different number of planes representing the same data, if there is a linear combination mapping between the two, we should be able to find it easily as simultaneous linear equations, using the \ operator.
When we examine the target image, we find that it is larger than the original. Closer examination shows that there are 4 leading rows of white, 1 trailing row of white, 2 leading columns of white, and 2 trailing columns of white. We can trim those out, but we are left with the difficulty that the trimmed target has one more row than the original. So we can proceed in one of three ways: assume that the extra is the top row; assume that the extra is the bottom row; or resize to match.
z4 = imread('zh12.tif');
[r, c, p] = size(z4);
z3 = imread('Capture.PNG');
z3a = z3(5:end-2,3:end-2,:); %extra is bottom row
z3b = z3(6:end-1,3:end-2,:); %extra is top row
z3c = imresize( z3(5:end-1,3:end-2,:), [r, c]); %resize to match
A = reshape(double(z4),[],4); A(:,5) = 1;
ba = reshape(double(z3a),[],3);
bb = reshape(double(z3b),[],3);
bc = reshape(double(z3c),[],3);
coeffsa = A\ba;
coeffsb = A\bb;
coeffsc = A\bc;
The coeffs will look like,
fprintf('%8.3f %8.3f %8.3f\n', coeffsa.')
0.516 -0.277 -0.072
0.034 0.514 -0.107
0.112 0.090 0.677
-0.040 -0.026 -0.007
-46.806 -14.479 14.012
which indicates that z3a(:,:,1) is about 0.516 * z4(:,:,1) + 0.34 * z4(:,:,2) + 0.112 * z4(:,:,3) - 0.04 * z4(:,:,4) - 48.806
The coefficients vary for the three versions, and there are negative values, but the pattern of the signs (negative vs positive) remains the same, so it would appear to be a true feature of the calculation, that subtractions are needed as well as additions.
predicta = uint8(reshape(A*coeffsa, r, c, 3));
predictb = uint8(reshape(A*coeffsb, r, c, 3));
predictc = uint8(reshape(A*coeffsc, r, c, 3));
figure('name', 'predict, bottom is extra'); imshow(predicta);
figure('name','orig minus predict, bottom is extra'); imshow(imsubtract(z3a,predicta), []);
figure('name','predict minus orig, bottom is extra'); imshow(imsubtract(predicta,z3a));
figure('name', 'predict, top is extra'); imshow(predictb);
figure('name','orig minus predict, top is extra'); imshow(imsubtract(z3b,predictb));
figure('name','predict minus orig, top is extra'); imshow(imsubtract(predictb,z3b));
figure('name', 'predict, resize'); imshow(predictc);
figure('name','orig minus predict, resize'); imshow(imsubtract(z3c,predictc));
figure('name','predict minus orig, resize'); imshow(imsubtract(predictc,z3c));
Graphically, the results are most black for "top is extra", indicating the least discrepancy with coeffsb. There are still some differences that are not immediately explicable; a part of it has to do with the green crosshairs in the target image.
Jan
am 25 Jun. 2017
Itrain = double(imread('zh12.tif'));
figure
for k = 1:4
Itrain(:, :, k) = Itrain(:, :, k) / max(max(Itrain(:, :, k)));
subplot(2,2,k);
imagesc(Itrain(:, :, k));
end
I do not see how these channels can be combined directly to obtain the shown output. Some scaling or perhaps a subtraction of channels might be required. Do you find something in the documentation of the used program?
0 Kommentare
Image Analyst
am 25 Jun. 2017
It looks like this is a multispectral image, not an RGB image. So you'll have to figure out how to combine the 4 spectral bands into a 3 band color image. Note that there are lots of ways to do that and they will not in general give you the same RGB image you'd get from a visible light RGB camera, since some of the bands in your image might be representative of infrared reflectance, not visible bands like R, G, and B. Go here:
for a discussion of how to combine different channels into an RGB image.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Color finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!