Divide an image vertically into two equally luminous parts, ..., calculate the luminance of each part.., PERSONAL NON-FUNDED RESEARCH,

9 views (last 30 days)
THIS IS NOT HOMEWORK. PERSONAL NON-FUNDED RESEARCH I will definitely give the person who answers this and matlab community acknowledgement
a. convert a picture to gray scale
rgbImage = imread('photo.jpg');
grayImage = rgb2gray(rgbImage);
b. divide the picture vertically such that the two parts (left and right) have equal luminance
c. . bisect each part so that there are now four parts to this picture Upper left, Upper right, lower left lower right
and. obtain the average luminance of each part.
d. obtain the vector of luminance for each part:: the luminance value multiplied by the distance from the point of intersection to the geometric center of the respective part.
e. However, for the two upper parts, the x,y value of this vector is replaced by x,(1.07)y. in other words the vertical component is lightened by 1.07
f.. add the four resultant vectors to obtain the distance from the intersection
Could you please provide the script for a "photo.jpg" so I could insert my own file. I have trouble running it backwards.
  4 Comments
Image Analyst
Image Analyst on 28 Jun 2022
@DGM I guess it doesn't show up when you click his name because Matt closed that thread.
@David Corwin do any of the answers below help?

Sign in to comment.

Accepted Answer

David Corwin
David Corwin on 1 Jul 2022
bisecting means that each part will have an equal number of rows.
dividing a picture so that each part will have equal average luminosity will of necessity mean that unless the picture is perfectly balanced, it will have different number of columns. Using photoshop I can do this with considerable accuracy. For example the figure 20 117.76 127.27 115.96 143.58.tif has an average luminance of 126.32. It can be divided into two parts 126.23 and 126.225
Four parts Upper left, upper right Lower left lower right 127.7 120.56 123.94 131.89 average 126.0225
Upper left is 297x213 px, upper right is 297x565 px lower left is 297x213 lower right is 297x565 px
the picture is 594 x 778
The picture 10 140.65 140.63 149.79 149.73 1.065 is viturally perfectly balanced
  5 Comments

Sign in to comment.

More Answers (5)

Image Analyst
Image Analyst on 28 Jun 2022
Edited: Image Analyst on 28 Jun 2022
Here's a start. See if you can finish it:
% Initialization Steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
folder = [];
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(rgbImage)
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 2, 1);
imshow(rgbImage);
impixelinfo;
axis('on', 'image');
title('Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
fprintf('It is not really gray scale like we expected - it is color\n');
% Extract the blue channel.
grayImage = rgbImage(:, :, 3);
else
grayImage = rgbImage;
end
% Update the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
% Maximize window.
g = gcf;
g.WindowState = 'maximized';
drawnow;
%--------------------------------------------------------------------------------------------------------
% Get means for each "half"
meanLeft = nan(1, columns);
meanRight = nan(1, columns);
for col = 2 : columns
meanLeft(col) = mean2(grayImage(:, 1:col))
meanRight(col) = mean2(grayImage(:, col+1:end))
end
subplot(2, 2, 2);
plot(meanLeft, 'b-', 'LineWidth', 2);
hold on;
grid on;
plot(meanRight, 'r-', 'LineWidth', 2);
legend('Left Rectangle', 'Right Rectangle', 'Location','southwest')
xlabel('Dividing Column', 'FontSize',fontSize)
ylabel('Mean Gray Level', 'FontSize',fontSize)
%--------------------------------------------------------------------------------------------------------
% Obviously you need to find where they cross.
% Be aware that there may be several dividing columns where the cross
% and the left intensity will equal the right intensity.
% So in that case just use min(abs(meanLeft-meanRight)) to find out the index of the closest match.
[~, bestColumn] = min(abs(meanLeft - meanRight))
xline(bestColumn, 'Color', 'g', 'LineWidth', 2)
subplot(2, 2, 1);
xline(bestColumn, 'Color', 'g', 'LineWidth', 2)
leftImage = grayImage(:, 1:bestColumn);
rightImage = grayImage(:, bestColumn+1:end);
% Display the image.
subplot(2, 2, 3);
imshow(leftImage);
caption = sprintf('Mean = %.3f', meanLeft(bestColumn));
title(caption, 'FontSize', fontSize);
subplot(2, 2, 4);
imshow(rightImage);
caption = sprintf('Mean = %.3f', meanRight(bestColumn));
title(caption, 'FontSize', fontSize);
%--------------------------------------------------------------------------------------------------------
% c. Bisect each part so that there are now four parts to this picture
% Upper left, Upper right, lower left lower right
midRow = round(rows/2);
partUL = leftImage(1:midRow, :);
partLL = leftImage(midRow+1:end, :);
partUR = rightImage(1:midRow, :);
partLR = rightImage(midRow+1:end, :);
% and obtain the average luminance of each part.
meanUL = mean2(partUL)
meanLL = mean2(partLL)
meanUR = mean2(partUR)
meanLR = mean2(partLR)
%--------------------------------------------------------------------------------------------------------
% I have no idea what any of the rest of this means.
% d. Obtain the vector of luminance for each part::
% the luminance value multiplied by the distance
% from the point of intersection to the geometric center of the respective part.
% What is the intersection point and what is "the geometric center"? You mena the weighted centroid?
% e. However, for the two upper parts, the x,y value of this vector is replaced by x,(1.07)y. in other words the vertical component is lightened by 1.07
% f. Add the four resultant vectors to obtain the distance from the intersection

Walter Roberson
Walter Roberson on 28 Jun 2022
Edited: Walter Roberson on 28 Jun 2022
"divide the picture vertically such that the two parts (left and right) have equal luminance"
Consider a checkerboard pattern with an even number of rows . If there were an even number of columns then if you divided in the center then the left and right would be identical and so their luminance would be the same. But if the number of columns is odd then when you divide one side has more columns than the other and the luminance cannot be equal.
Therefore the task is not generally possible.
  12 Comments
Walter Roberson
Walter Roberson on 29 Jun 2022
Means.
peppers only has one balance point; baby.jpg has two balance points, both much further right than you would expect.
format long g
img = imread('peppers.png');
LAB = rgb2lab(img);
L = LAB(:,:,1);
sL = sum(L, 1);
forward = cumsum(sL) ./ (1:length(sL));
backward = fliplr( cumsum(fliplr(sL)) ./ (1:length(sL)) );
difference = forward - backward;
[~, bestidx] = min(abs(difference))
bestidx =
243
imshow(img)
xline(bestidx);
figure()
plot(difference)

Sign in to comment.


DGM
DGM on 28 Jun 2022
Edited: DGM on 28 Jun 2022
I'm just going to repost this here, since all the cool kids are posting on this one and the other one is closed anyway. :)
A = imread('peppers.png');
A = rgb2gray(A); % BT601 luma
A = im2double(A);
% split the image into two halves of approx equal weight
Aps = cumsum(sum(A,1),2); % cumulative sum of image profile
lastidx = find(Aps<=(max(Aps)/2),1,'last');
Aw = A(:,1:lastidx); % west half
Ae = A(:,lastidx+1:end); % east half
% show the weights are close to equal
[sum(Aw,'all') sum(Ae,'all')]
ans = 1×2
1.0e+04 * 3.1441 3.1520
% bisect halves
hh = round(size(A,1)/2);
Anw = Aw(1:hh,:);
Asw = Aw(hh+1:end,:);
Ane = Ae(1:hh,:);
Ase = Ae(hh+1:end,:);
% average luma for each quarter [nw; sw; ne; se]
allluma = [mean(Anw,'all'); mean(Anw,'all');
mean(Ane,'all'); mean(Ase,'all')]
allluma = 4×1
0.2731 0.2731 0.3089 0.3225
% find geometric center vectors
center = [lastidx hh]; % [x y]
allv = [center/2; % [nw; sw; ne; se]
lastidx/2 hh*1.5;
lastidx*1.5 hh/2;
center*1.5];
allv = (allv - center).*[1 1.07; 1 1; 1 1.07; 1 1]
allv = 4×2
-126.0000 -102.7200 -126.0000 96.0000 126.0000 -102.7200 126.0000 96.0000
% weight center vectors by luma
allv = allv.*allluma
allv = 4×2
-34.4152 -28.0565 -34.4152 26.2211 38.9191 -31.7284 40.6378 30.9621
% find the sum
sumv = sum(allv,1)
sumv = 1×2
10.7266 -2.6017
  12 Comments
Walter Roberson
Walter Roberson on 30 Jun 2022
What are you going to do with that information?
The wording suggested a homework assignment to me; if so then there might not be any good reason.

Sign in to comment.


David Corwin
David Corwin on 30 Jun 2022
The picture is divided into two parts each having the same average luminance (right and left). The picture is them bisected. In a ~perfectly balanced picture such as the example, the lower quadran is 1.07xluminance of the upper quadrants. In the example I used for you it was 1.06 This is being measured by photoshops luminance measure which I presume is the luminance of all the pixels divided by the number of pixels - the average luminance. The rectangular marquee tool is used to define the quadrant and the histogram luminosity channel is used to measure luminance.
I would be happy to upload the images but not sure how. They can be found in the supplemental files of the paper but it would be easier for me to just upload a few. The paper takes you through the logic of determining pictorial balance using a center of quadrant balance type of equation. However, at the end I suggest that the visual system might determine it in another way which takes into account irregularly shaped objects. In light of this way of measuring pictorial balance I would like to recalculate balance of the pictures used in the study.
  3 Comments
DGM
DGM on 2 Jul 2022
Edited: DGM on 2 Jul 2022
For what it's worth, I'm just going to guess that that's BT2020 luma; at least it's the closest thing I can come up with.
inpict = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1052950/20%20117.76%20127.27%20115.96%20143.58.jpg');
Ay2020 = [0.2627 0.6780 0.0593];
inpict = imapplymatrix(Ay2020,inpict);
mean(inpict(:))
ans = 126.3939
Just looking at an average means I could be completely wrong though.

Sign in to comment.


David Corwin
David Corwin on 23 Jul 2022
Could you add to that code to give also the distance from the pictures geometric center? BTW photoshop uses BT2020 luma;
  5 Comments

Sign in to comment.

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!