Color JPG image saved by imwrite() incompatible with Web Browser.
Show older comments
Hello There,
I am trying to read a file from the server and display on the webpage using JSP. The file is created using imwrite(). I have tried .jpg and .png. I have tried grayscale (8-bit depth) and color (24-bit depth). I have tried on Internet Explorer and Google Chrome. Nothing works and the image is not displayed. I have no problems displaying images downloaded from the internet.
I presume there is something in the file format that is causing all this problem. If required, I could email two .jpg file, one that works fine and the other that does not.
The MATLAB code used to create this image is:
imwrite(g,'../image/image.jpg');
Please help.
Thanks and Regards.
JSP code below:
<!DOCTYPE html>
<%@ page import="java.util.*" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.io.File" %>
<%@ page import="java.io.*" %>
<%@ page language="java" import="java.util.*"%>
<head>
<script language="JavaScript">
var refreshImageFlag;
function refreshFlagEnable(){
refreshImageFlag = true;
}
function refreshFlagDisable(){
refreshImageFlag = false;
}
function refreshIt() {
if (!document.images) return;
if(refreshImageFlag == true){
tmp = new Date();
document.images['myCam'].src = "C:\\WebDev\\uploads\\image\\image.jpg" + "?" + tmp.getTime();
}
}
</script>
</head>
<BODY onLoad="setInterval('refreshIt()',1000);">
<<C---WebDev--uploads--image--image.jpg>>
<FORM NAME="form1" METHOD="POST">
<input type="button" value="StartRefresh" onclick="refreshFlagEnable();"/>
<input type="button" value="StopRefresh" onclick="refreshFlagDisable();"/>
</FORM>
<<C---WebDev--uploads--image--image.jpg>>
</BODY>
Answers (2)
Walter Roberson
on 21 Oct 2011
img src="file:///C:\WebDev\uploads\image\image.jpg"
9 Comments
Protik Maitra
on 24 Oct 2011
Walter Roberson
on 24 Oct 2011
What happens if you read a jpg file using imread() and then write it out (with a different name) using imwrite() ? Compare imageinfo() of the two [if you have the Image Processing Toolbox]
Protik Maitra
on 24 Oct 2011
Moved: Rena Berman
on 28 Dec 2023
Protik Maitra
on 24 Oct 2011
Protik Maitra
on 24 Oct 2011
Moved: Rena Berman
on 28 Dec 2023
Protik Maitra
on 24 Oct 2011
Walter Roberson
on 24 Oct 2011
Moved: Rena Berman
on 28 Dec 2023
The characteristics _look_ okay.
I suggest trying doing the imwrite() with the JPEG-specific parameter 'Quality', 100
I also suggest trying imwrite with 'mode', 'lossless'
I cannot think of any reason that the images might be incompatible, but we might at least be able to figure out the file size difference.
Also there is a routine imfinfo() which should tell you details such as the EXIF tags.
Protik Maitra
on 26 Oct 2011
Moved: Rena Berman
on 28 Dec 2023
Protik Maitra
on 26 Oct 2011
Moved: Rena Berman
on 28 Dec 2023
Richard Zapor
on 20 Dec 2011
0 votes
The array may be lacking the full data structure. The site http://radio.feld.cvut.cz/matlab/techdoc/printing/export21.html gives a method for establishing the structure and then using imwrite to produce a valid jpg.
figure;imagesc(data) I = getframe(gcf); imwrite(I.cdata, 'myplot.jpg', 'Quality', 50);
Categories
Find more on Web Services 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!