Resize image using imresize gives an error in octave - arrays

I'm trying to resize a very small image using Octave 5.2.0 but I'm not sure why it's giving an error when trying to resize it
The error happens with the line below:
img_unique_only = imresize(f2, [640, 480]); %reshape output of unique colors
error: interp2: cubic requires at least 2 points in each dimension
error: called from
interp2 at line 244 column 9
imremap at line 65 column 19
imresize at line 135 column 8
test_small_resize_question at line 30 column 17 (the last line which is the imresize line)
Code Below:
pkg load image
f(:,:,1)=[0;0;0;0;127;128;128;128];
f(:,:,2)=[0;0;127;128;0;0;0;0];
f(:,:,3)=[127;128;0;0;0;0;127;128];
%%%%%%%%%%%%%%%%-------------------------------------------------------------------------
[im_r im_c]=size(f);
size_min=min(im_r,im_c); %get minum size from row and col
f2=uint8(f)
imshow(f2)
img_unique_only = imresize(f2, [640, 480]); %reshape output of unique colors
Using imshow(f2) creates the image below
The Line img_unique_only = imresize(f2, [640, 480]); %reshape output of unique colors won't resize it
Variables created:
When using the line img_unique_only = imresize(f2, [640, 480], "nearest"); %reshape output of unique colors
Variables created:
I get a gray scale image instead of a 640x480 color image
Note: I'm also willing to try another way if better

A work around is to use cat Note: it creates a gradient of colors that aren't correct.
f(:,:,1)=[0;0;0;0;127;128;128;128];
f(:,:,2)=[0;0;127;128;0;0;0;0];
f(:,:,3)=[127;128;0;0;0;0;127;128];
height_wanted=640;
width_wanted=480;
repmat_rgb=cat(2,f,f); %add another column to array to get imresize to work
reshaped_output = imresize(repmat_rgb, [height_wanted, width_wanted],'cubic'); %reshape swatch to large output
imshow(reshaped_output);
Update: July 19 2021
It's a bug in imresize for more info and workaround
Matrix array to multidimensional RGB image array and using imresize to reshape image

Related

After an image is resized within a PictureBox how do you get the adjusted image size and location?

Im using Win Forms to do a quick little GUI for a powershell script...
In terms of the PictureBox Control, is it possible to get the image size and position information of the Adjusted image size, within the picturebox?
Quick example: Say a picturebox control is 300x300. Im using the Zoom attribute to maintain the aspect ratio of each image that is placed in the picture box. Let's say the image is 4000 x 2500. Once that image is reduced, I'd like to know its final size and coordinates. Anything I have tried so far seems to only return the original size of the image.
You could calculate this yourself if the width and height of both the picturebox and the original image are known:
# size of the Picturebox the image should fit in
$boxWidth = 300 # $pictureBox.Width
$boxHeight = 300 # $pictureBox.Height
# size of the original image
$imageWidth = 4000 # $pictureBox.Image.Width
$imageHeight = 2500 # $pictureBox.Image.Height
# calculate the image ratio
$ratioX = [double]($boxWidth / $imageWidth)
$ratioY = [double]($boxHeight / $imageHeight)
$ratio = [Math]::Min($ratioX, $ratioY)
# calculate the resulting image size
$newWidth = [int]($imageWidth * $ratio)
$newHeight = [int]($imageHeight * $ratio)
Result:
$newWidth --> 300
$newHeight --> 188

MATLAB - save image in structure array array{i,y} and retrieve with (image(i,y))?

My system:
Windows 8.1
MATLAB2015a
My issue: When I save a JPG image in a structure array, in this case stiAll{i,y}
fileName = strcat('group_',strGr,'_',strVal,'.jpg');
fileNameStr = char(fileName);
stiAll{i,y} = imread(fileNameStr);
and I try to retrieve the saved image with image(stiAll(i,y)) I get the following error message from MATLAB:
Invalid datatype for Image CData. Numeric or logical
matrix required for image CData.
If I save the image without the {i,y} suffix, so that the image is saved in a normal variable, not in a structure array, I can retrieve the image. However, for my programme I would need to save images in the respective cells of a structure array or something similar.
Any idea how to get this done successfully?
Thanks
J
stiAll{i,y} = imread(fileNameStr); looks like a cellArray. And you try to plot it image(stiAll(i,y)) now as Matrix. Try image(stiAll{i,y})

Cocos 2d CCMenu to appear

I want to use a image for 80 times (same Image) Instead of adding CCMenu 80 time there is any alternate way.
CCMenuItemImage tile=CCMenuItemImage.item("1.png","1.png");
tile.setScaleX(1.0f);
tile.setScaleY(1.0f);
tile.setPosition(CGPoint.ccp(screenSize.width-630*generalscalefactor,405));

.raw file in Paraview

I have downloaded a .raw datafile that I want to view in Paraview.
The dataset I'm using is taken from:
http://volvis.org/ -> download dataset -> CT Scan of bonsaitree.
Whenever I import the dataset I do as explained here in this link:
http://www.paraview.org/Wiki/ParaView/Data_formats#Raw_files
Everything goes fine until I hit apply. I then get these two error messages, and the view is empty:
ERROR: In C:\DBD\pvs-x64\paraview\src\paraview\ParaViewCore\VTKExtensions\Rendering\vtkTexturePainter.cxx, line 295
vtkTexturePainter (00000000136105F0): Incorrect dimensionality.
Warning: In C:\DBD\pvs-x64\paraview\src\paraview\VTK\Rendering\Core\vtkRenderer.cxx, line 1030
vtkOpenGLRenderer (0000000009CF08C0): Resetting view-up since view plane normal is parallel
How do I get rid of these error messages?
A raw file does not have a header with information about the data inside (orientation, dimension...). You have to provide that information, and it has to be compatible with the content of the image. I tried a couple of time with the data you provided and succeeded with the following parameters:
when prompted reader: raw binary file (I just checked the file content with notepad)
data extent: 0 255 0 255 0 255 (the website says that the image is 256x256x256)
data scalar type: char (I confess that I just guessed it at the first time, a more correct way would be to multiply the data type by the number of voxels and compare it with the file dimension).

Custom heightForRowAtIndexPath (CGSize sizeWithFont) with NSAttributedString iOS

I have a table view where my cells height is defined dynamically depending on the text it is representing.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//getting my text for this cell, the row etc ...
...
//here is the part interesting us
NSAttributedString* theText = [myTextForThisCell objectAtIndex:indexPath.row];
NSInteger labelWidth = self.tableView.bounds.size.width-HORIZONTAL_CELL_PADDING;
CGSize textSize = [theText sizeWithFont:[UIFont systemFontOfSize:customFontSize] constrainedToSize:CGSizeMake(labelWidth, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];
return textSize.height+VERTICAL_CELL_PADDING;
}
Ok so now my problem.
The tableview is the result of a search action which after scanning a plist file shows the lines containing a given string.
Up to now that was it. But now with iOS 6 and NSAttributedString allowing easily to bold part of strings I decided to bold the search word.
It is working, it bolds the words I want but now I am no more able to calculate the cell height as sizeWithFont ask for a NSString. And as bolding takes a wider width I cannot simply calculate the cell height with the string without attributes.
I am simply stuck here.
Anyone can help me ?
In fact I simply had to read apple documentation of NSAttributedText.
In my case I have to replace the last two lines of code by
CGRect rectSize = [theText boundingRectWithSize:CGSizeMake(labelWidth, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin context:NULL];
return rectSize.size.height+VERTICAL_CELL_PADDING;
FOLLOW UP iOS 7
I have been struggling making this work in iOS7 with attributed text.
Apple documentation says
In iOS 7 and later, this method returns fractional sizes (in the size
component of the returned CGRect); to use a returned size to size
views, you must use raise its value to the nearest higher integer
using the ceil function.
Which way obviously not working for me ! For me the solution was to add +1 to the ceil of height. This is probably a bug from Apple, but for me now everything works as in iOS6.
CGRect rectSize = [theAttributedText boundingRectWithSize:CGSizeMake(labelWidth, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin context:NULL];
return ceil(rectSize.size.height) + 1 + VERTICAL_CELL_PADDING;

Resources