How do you make a gray scale image more continuous?

5 views (last 30 days)
I have this code that plots x and y points and assigns intensity on the gray scale. I would like to know how to make this image more continuous. I have attached an image to this question. You'll notice that there are short lines, but I want a more continuously shaded image. Below is my code:
% Make an image of the points, then apply a colormap
x = X(:); % Extract x value
y = Y(:); % Extract y value
v=v(:); %must be imported as a double with NaN's replaced with zeros
%find max and min values
minX = min(x,[],1);
maxX = max(x,[],1);
minY = min(y,[],1);
maxY = max(y,[],1);
minV=min(v,[],1);
maxV=max(v,[],1);
% Make image be 500 by 700
rows = 500;
columns = 500;
grayImage = zeros(rows, columns, 'uint8');
for k = 1 : 44641
row = ceil((y(k) - minY) * rows / (maxY - minY));
column = ceil((x(k) - minX) * columns / (maxX - minX));
if (row == 0)
row = 1;
end
if (column == 0)
column = 1;
end
grayImage(row, column) = int8(maxV * (v(k) - minV) / (maxV - minV));
end
imshow(grayImage);
  2 Comments
OCDER
OCDER on 26 Sep 2017
Edited: OCDER on 26 Sep 2017
So what's X, Y, and v? Also, I see you're using int8 for a calculation when grayImage is uint8.
grayImage(row, column) = int8(maxV * (v(k) - minV) / (maxV - minV));
%change to
grayImage(row, column) = uint8(maxV * (v(k) - minV) / (maxV - minV));
int8 will cap the max value at 127, whereas uint8 can go up to 255, which would restrict the level of grayness you can achieve by half. If you need precise intensity calculations and speed is not an issue, use double units for grayImage and then convert to uint8 right before you have to save the image.
About the more "continuous" image, looks like the discontinuity are governed by the way you calculated row and column, and the increment governed by these terms here:
* rows / (maxY - minY))
* columns / (maxX - minX));
Without knowing X, Y, v and where the equations for row and column came from, it'll be hard to provide more guidance. But start by reworking these equations until you get the results you want.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!