image quality different in matlab

2 views (last 30 days)
Miles Brim
Miles Brim on 1 Jun 2023
Commented: Miles Brim on 1 Jun 2023
I have the following code. It generates a figure and then converts it into a pixel array "X". In another program I read that pixel array into a Java image and display it at the same resolution. The image qualities are very different. Why is this? How can I fix it? The first picture below is the figure in MATLAB, the second is the figure in Java.
fig=figure;
plot(L,mah)
hold
scatter(L(outliers==1),mah(outliers==1),'o')
legend(["Measurements","Outliers"])
xlabel("Measurement Sequence")
ylabel("Mahalanobis Distance")
title("Outlier Plot - Minimum Covariance Determinant Method")
set(gcf,'Position',[100 100 1120 840])
F = getframe(gcf);
[X, ~] = frame2im(F);
  3 Comments
Miles Brim
Miles Brim on 1 Jun 2023
Technically it is jython. I beleive I am doing this correctly. On the application forum, It was suggested that MATLAB may be using antialiasing. Is there a way to capture the pixels after antialiasing?
The pixel array is passed by the MPS API to the other application.
I build the Buffered Image from the pixel array.
IMG=Result[5].get('mwdata')
IMGSize=Result[5].get('mwsize')
IMGType=Result[5].get('mwtype')
Img=[[[0, 0, 0] for i in range(IMGSize[1])] for j in range(IMGSize[0])]
n=-1
for k in range(IMGSize[2]):
for j in range(IMGSize[1]):
for i in range(IMGSize[0]):
n+=1
Img[i][j][k]=IMG[n]
image = BufferedImage(IMGSize[1], IMGSize[0], BufferedImage.TYPE_INT_RGB);
raster = image.getData();
sm = raster.getSampleModel();
writeRaster = Raster.createWritableRaster(sm,Point(0,0))
for i in range(IMGSize[1]):
for j in range(IMGSize[0]):
for k in range(IMGSize[2]):
writeRaster.setSample(i, j, k, Img[j][i][k])
image.setData(writeRaster);
event.source.parent.getComponent('Figure').putClientProperty('Picture',image)
I then display it accordingly:
image = event.source.getClientProperty("Picture")
if image:
canvasW = event.width
canvasH = event.height
imageW = image.getWidth()
imageH = image.getHeight()
scaleX = (canvasW-1.0) / imageW
scaleY = (canvasH-1.0) / imageH
g = event.graphics
g.scale(scaleX, scaleY)
g.drawImage(image,0,0,event.source)
Miles Brim
Miles Brim on 1 Jun 2023
OK, yes, I know it is matlab: Here are the two images, one with graphics smoothing turned off.
fig.GraphicsSmoothing = 'off';

Sign in to comment.

Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!