Clear Filters
Clear Filters

Pixelwise brightness adjustment using another image (weights)

4 views (last 30 days)
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 Comments
Francisco E. Enríquez Mier y Terán
Hi DGM,
Thanks for your comments here. I'm doing the following:
% imdata 1: image data to display
% imdata2: matrix of weights
% image_w: colourmapped image data (RGB) with imdata2 weighting
f= figure; colormap jet;
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)
%for one pixel: row,col indexes:
pval = imdata1(row,col);
%Weighting happens here:
image_w(row,col) = cmap(pval,:)*imdata2(row,col);
I'll reconsider my approach and my final goal then!
Thanks,
Francisco
DGM
DGM on 11 Nov 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)

Sign in to comment.

Answers (2)

DGM
DGM on 11 Nov 2021
Edited: DGM on 11 Nov 2021
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))]

yanqi liu
yanqi liu on 12 Nov 2021
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 Comment
DGM
DGM on 12 Nov 2021
Edited: DGM on 12 Nov 2021
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.

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!