Filter löschen
Filter löschen

Set size of image without border and save

9 Ansichten (letzte 30 Tage)
md khan
md khan am 2 Mai 2020
Kommentiert: Ameer Hamza am 2 Mai 2020
I have an original.jpg of size (320 * 240). After plotting some line on the image I get processed.jpg. But the size of processed.jpg is (504 * 353) with white border.
I need to processed.jpg to be the same size as original.jpg WITHOUT any white border. How to do that?
Attached is the code used to draw lines over the original image. I am using 2019a
img = imread('C:\Users\khan1\jupyter_test_code\CRBD\Images\crop_row_274.JPG');
data = load('C:\Users\khan1\jupyter_test_code\CRBD\TMGEM results\crop_row_274.tmg');
fig = figure;
imshow(img);
hold on
plot(data, 1:size(data,1), 'r', 'LineWidth', 1);

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 2 Mai 2020
Bearbeitet: Ameer Hamza am 2 Mai 2020
I guess you are use getframe to save the image with 3 lines. getframe cannot keep the resolution of the original image. You may use imresize(), but that will modify your original image to some extent. If you have computer vision toolbox, then you can use insertShape() to fuse the lines into the pixel of the image directly.
img = imread('crop_row_001.JPG');
data = load('crop_row_001.tmg').';
data2 = zeros(size(data,1), size(data,2)*2);
data2(:,1:2:end) = data;
data2(:,2:2:end) = repmat(1:size(data,2), size(data,1), 1);
img = insertShape(img, 'Line', data2, 'Color', 'r', 'LineWidth', 1);
imshow(img);
imwrite(img, 'filename')
P.S.: I used the image and data file from your other question, which I answered.
The attached image has resolution of 320 * 240.
  2 Kommentare
md khan
md khan am 2 Mai 2020
Bearbeitet: md khan am 2 Mai 2020
Thank you. But my figure do not have any redlines. What am I missing?
I see now! "load('crop_row_001.tmg').';:" is different. It works now. thanks!
Ameer Hamza
Ameer Hamza am 2 Mai 2020
I am glad to be of help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 2 Mai 2020
Burning red dots into pixels does NOT change the size of the image. You must have done something else. Either burn the dots into the image,
rgbBurned = rgbImage; % Initialize to the original image with no graphics.
for k = 1 : length(x)
row = round(y);
col = round(y);
% Burn a red dot in.
rgbBurned(row, col, 1) = 255;
rgbBurned(row, col, 2) = 0;
rgbBurned(row, col, 3) = 0;
end
imwrite(rgbBurned, newFileName);
or call exportgraphics().

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by