Pixelwise brightness adjustment using another image (weights)
Mostrar comentarios más antiguos
HI,
I have two matrices (images, n-by-n elements each) that I want to combine - The first image is the parameter of interest (e.g. T2 values, for MRI images) and the second one is a fractional volume that I want to use as a weighting for the first image. I have manage to create the desired image by scaling the values of my first image from 0 -1, assigning it's corresponding colour using a colormap (jet) and then multiplying each pixel/RGB-colours using the fractional volumes. The above gives me an image that has been brightened properly, however it suffers from an issue - The new images, which are RGB, do not display the pixel vulue of the original image; which makes sense based on what I'm doing.
The question then is: Is there a way to adjust the brightness of each pixel, intrinsically, without modifiying my pixel values?
Thanks,
Francisco
3 comentarios
Let me see if I'm getting this about right. You're doing something like this:
A = imread('cameraman.tif'); % grayscale image
Argb = ind2rgb(A,jet(256)); % represent in false color
% simple horizontal gradient as weighting
B = repmat(linspace(0,1,size(A,2)),[256,1]);
C = Argb.*B; % apply weighting
imshow(C)
If you want to be able to simply use tooltips or something similar to extract the values of A by inspecting C, you're going to have to do it some other way. Since the weighting imposed by B is independent of the indices in A, I don't see a way to do this by encoding things into the colormap. For example, in the above example, pixels which once had the same index
[A(107,40) A(112,119)]
[squeeze(C(107,40,:)) squeeze(C(112,119,:))].'
No longer have the same colors. There isn't a way for C to have one index that refers to two colors in a colormap.
If you're trying to build a GUI that allows interactive data inspection, you may be able to use coordinate information to simply look up the values in A while displaying C.
Francisco E. Enríquez Mier y Terán
el 11 de Nov. de 2021
Yeah, that's basically a roundabout way of doing the ind2rgb conversion. Not that it solves the underlying problem, I'd just figure I'd demonstrate that the result is the same as the example I posted above.
cmap = jet(256); % don't need to bump the figure to get the cmap
imdata1 = double(imread('cameraman.tif')); % same as before
imdata2 = repmat(linspace(0,1,size(imdata1,2)),[256,1]); % same as before
imdata1 = 255 * imdata1/max(imdata1(:)); % range is 0 - 255
imdata1 = floor(imdata1 + 1); % range is 1 - 256 (integer)
s = size(imdata1);
cmap = permute(cmap,[1 3 2]);
for row = 1:s(1)
for col = 1:s(2)
%for one pixel: row,col indexes:
pval = imdata1(row,col);
%Weighting happens here:
image_w(row,col,:) = cmap(pval,1,:)*imdata2(row,col);
end
end
imshow(image_w)
Respuestas (2)
This might be of use as an example. The original image has large flat regions of solid color, but the weighted image does not. By clicking on the displayed image, you can look up the values in the original image instead of the image that's displayed. Just run the script, click two different points in one region, and observe the result.
A = imread('toyobjects.png'); % grayscale image
Argb = ind2rgb(A,jet(256)); % represent in false color
% simple horizontal gradient as weighting
B = repmat(linspace(0,1,size(A,2)),[size(A,1) 1]);
C = Argb.*B; % apply weighting
imshow(C) % show the weighted image
[x y] = ginput(2); % pick 2 points from within any given region
x = round(x); % rounding is simple, but beware of what happens at edges
y = round(y);
% the colors displayed are different
squeeze([C(y(1),x(1),:); C(y(2),x(2),:)])
% but the indices in A are the same
[A(y(1),x(1)); A(y(2),x(2))]
clc; clear all; close all;
imdata1 = double(imread('cameraman.tif'));
row = size(imdata1,1);
col = size(imdata1,2);
imdata2 = double(imread('rice.png'));
% imdata 1: image data to display
% imdata2: matrix of weights
% image_w: colourmapped image data (RGB) with imdata2 weighting
f= figure; colormap( jet(256) );
cmap = colormap(f); % 256 x 3 matrix
close(f);
imdata1 = 255 * imdata1/max(imdata1(:)); % range is 0 - 255
imdata1 = floor(imdata1 + 1); % range is 1 - 256 (integer)
image_w = [];
for i = 1 : row
for j = 1 : col
%for one pixel: row,col indexes:
pval = imdata1(i,j);
%Weighting happens here:
image_w(i,j,:) = cmap(pval,:)*imdata2(i,j);
end
end
figure; imshow(image_w,[])
1 comentario
The image display is clipped because the implicit normalization syntax imshow(myimage,[]) doesn't work on RGB images. This can be fixed by simply making sure imdata2 is scaled [0 1] by using im2double() instead of double() when reading the image.

Of course, this still doesn't address the original question, which was about accessing the original image indices while viewing the composite image.
Categorías
Más información sobre Explore and Edit Images with Image Viewer App en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


